ユーザー権限のsystemdでauto loginしましょう
環境変数 XDG_RUNTIME_DIRにユーザーID(id -u your_usernameで取得するのが便利)をセットしましょう
$ export XDG_RUNTIME_DIR=/run/user/$(id -u $username)
ホームディレクトリにユーザモード用のsystemdディレクトリを作成しましょう
$ mkdir -p ~/.config/systemd/user
とりあえず仮想コンソール1(/dev/tty1)に自動でログインするサービスを記述します(サービス名は getty@tty1.serviceとしておきます)
$ cat ~/.config/systemd/user/getty@tty1.service
[Install]
WantedBy=default.target
[Service]
ExecStart=
ExecStart=/sbin/agetty –autologin $username –noclear %I 38400 linux
サービスを有効にします
$ systemctl –user daemon-reload
$ systemctl –user enable getty@tty1.service
$ systemctl –user list-dependencies
ユーザlingerを有効にします
$ loginctl enable-linger $(username)
再起動すると/dev/tty1で自動ログインされているはず
$ systemctl –user status
- yourPC
State: running
Units: 49 loaded (incl. loaded aliases)
Jobs: 0 queued
Failed: 0 units
Since: Thu 2025-02-06 17:56:51 JST; 29min ago
systemd: 252.33-1~deb12u1
CGroup: /user.slice/user-0.slice/user@1990.service
|-app.slice
|-app-getty.slice |-getty@tty1.service
| |-151 /bin/login -f
| |-156 -bash
| |-351 systemctl –user status
|-352 pager-init.scope
|-136 /lib/systemd/systemd –user
`-137 “(sd-pam)”
サービスを無効にするかユーザlingerを無効化すれば自動ログインされなくなります
$ systemctl –user enable getty@tty1.service
$ loginctl enable-linger username
Leave a Reply