How can I configure systemd to automatically log me in to my desktop environment, preferably without using a login manager? I'm using Arch Linux.
-
Which login manager are you using? Some (GDM, KDM, iirc, maybe more) already support autologin so you would only need to enable the service for them. – Wieland Jul 05 '12 at 10:24
-
I'm currently using SLiM and it can be configured to autologin, but without a display manager the boot process would be faster and more flickerless :) – fhucho Jul 05 '12 at 10:27
4 Answers
This is described in the ArchWiki:
Create a new service file similar to
[email protected]by copying it to/etc/systemd/system/cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/[email protected]
This basically copies the already existing [email protected] to a new file [email protected] which can be freely modified. It is copied to /etc/systemd/system because that's where site-specific unit files are stored. /usr/lib/systemd/system contains unit files provided by packages so you shouldn't change anything in there.
You will then have to symlink that [email protected] to the getty service for the tty on which you want to autologin, for examply for tty1:
ln -s /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]
Up to now, this is still the same as the usual [email protected] file, but the most important part is to modify the [email protected] to actually log you in automatically.
To do that, you only need to change the ExecStart line to read
ExecStart=-/sbin/agetty -a USERNAME %I 38400
The difference between the ExecStart line in [email protected] and [email protected] is only the -a USERNAME which tells agetty to log the user with the username USERNAME in automatically.
Now you only have to tell systemd to reload its daemon files and start the service:
systemctl daemon-reload
systemctl start [email protected]
(I'm not sure if the service will start properly if you're already logged in on tty1, the safest way is probably to just reboot instead of starting the service).
If you then want to automatically start X, insert the following snippet into your ~/.bash_profile (taken from the wiki again):
if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
exec startx
fi
You will have to modify your ~/.xinitrc to start your desktop environment, how to do that depends on the DE and is probably described in the ArchWiki as well.
- 7,797
- 7
- 45
- 54
- 6,353
- 3
- 28
- 31
-
1
-
2
-
use `ln -sf /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/[email protected]` to overwrite it. – Manuel Schmitzberger Nov 09 '19 at 14:23
IMO, the Arch Wiki currently recommends a much simpler solution:
Either run the helper (systemctl edit getty@tty1) or do what I did manually:
mkdir -p /etc/systemd/system/[email protected]/
touch /etc/systemd/system/[email protected]/override.conf
The text you want to enter (by either method) is (be sure to change username appropriately):
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin username --noclear %I $TERM
NOTE: The empty line is important! The empty line will first clear the ExecStart entry, while the next line will introduce a new exec command.
Now, restart (shutdown -r 0) and something to the effect of ... login: username (automatic login) will happen where it previously blocked waiting for username/password input
Once rebooted, and auto-logged in, if you're like me and want to SSH into this system now, you probably need to run:
systemctl enable sshd.service
Which will create the symlink (e.g. ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service')
- 66,199
- 35
- 114
- 250
- 201
- 2
- 5
-
The arch wiki also mentions that if you still want it to require a password, but you don't want to type your username, replace `--autologin username` with `--skip-login --login-options username` – cdgraham Apr 14 '20 at 17:20
-
Directly modify the file /etc/systemd/system/getty.target.wants/[email protected] (which is a symlink to /lib/systemd/system/getty@service):
Append -a/--autologin USERNAME to the line:
ExecStart=-/sbin/agetty --noclear %I $TERM
Hence:
ExecStart=-/sbin/agetty -a USERNAME %I $TERM
You might also remove -o '-p -- \\u' (as present on the current Arch installation) as this would start the login for USERNAME but still asks for the password.
After rebooting, you will be logged in automatically.
P.s. Change the filename [email protected] to the tty you want to log into.
-
Note for clarity: if it's a symlink, replace the symlink with a new file, and edit that new file. – Edward Anderson Dec 04 '16 at 04:28
You can also use getty (get tty) command which allows you to auto login the specified user automatically, the argument of the getty can be either --autologin or -a, I am running Linux Debian Ubuntu so I don't know if this command is available in other distros.
getty -a <user>