How can I configure systemd to automatically log me in to my desktop environment, preferably without using login manager? I'm using Arch.

  • 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 5 '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 5 '12 at 10:27
  • Oh, I misread your question. – Wieland Jul 5 '12 at 10:53
up vote 16 down vote accepted

This is described in the Arch Wiki:

Create a new service file similar to getty@.service by copying it to /etc/systemd/system/

cp /usr/lib/systemd/system/getty@.service /etc/systemd/system/autologin@.service

This basically copies the already existing getty@.service to a new file autologin@.service which can be freely modifed. 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 autologin@.service to the getty service for the tty on which you want to autologin, for examply for tty1:

ln -s /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service

Up to now, this is still the same as the usual getty@.service file, but the most important part is to modify the autologin@.service 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 getty@.service and autologin@.service 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 getty@tty1.service

(I'm not sure if the service will start properly if you're already logged in on tty1, the safest way is propably 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 Arch wiki as well.

  • What is the agetty arg %I? – Edward Anderson Dec 4 '16 at 4:26
  • Whats up with the ` charachter at the end? Is that needed? What does it mean? – rien333 Jul 21 at 16:40
  • @rien333 It's unnecessary, I've removed it from the answer. – Wieland Jul 21 at 18:08
  • I get the error File exists when I do the symlink – Post Self Oct 23 at 8:26

Directly modify the file /etc/systemd/system/getty.target.wants/getty@tty1.service (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 getty@tty1.service 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 4 '16 at 4:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.