Arch Linux 指定 tty 自动登录

在使用 WM 桌面环境的时候,配置 ttyN 指定跳过输入密码且自动执行 startx 无疑会带来更加好的体验。以下是参考 Arch Wiki 相关配置内容,书写的配置笔记。

直接运行

1
systemctl edit getty@tty1

其中 tty1 为指定的 tty

或者使用手动的方式编辑 getty@tty1 文件

1
2
mkdir -p /etc/systemd/system/[email protected]/
touch /etc/systemd/system/[email protected]/override.conf

最后在 /etc/systemd/system/[email protected]/override.conf 添加以下内容:

[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin username --noclear %I $TERM

这里的 ExecStart= 不要删掉,这里是先清除 ExecStart 原有的内容,然后在引入新的 exec 命令。

username 为你的用户的用户名称。

这个时候就实现了指定 tty 免密登录了。

接着就是配置 x11 默认执行 startx,根据 Arch Wiki 在指定 shell 初始化文件中添加以下代码:

Bash: ~/.bash_profile

Zsh: ~/.zprofile

官方配置:

1
2
3
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then
  exec startx
fi

我的配置:

1
2
3
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  exec startx
fi