Autologin to sway on debian

11 Nov 2023

Let's say all we want to do when our laptop boots up is to input the password for unlocking the disk and be straight away taken to your wayland or X11 desktop. Well then, let's go!

Start X or wayland on tty login

We are not going to be using a display manager like gdm3 or lightdm. So, when a user logs in into tty1, normally one would run sway or startx shortly after.

We can the use the shell the automate this for tty1 alone.

# automatically login into sway
if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then
  exec sway
  # exec startx

Put this snippet at the very end of your $HOME/.zprofile or $HOME/.bash_profile. Now when you log out and log back in, you should be presented with your desktop.

Autologin into your system

Run sudo systemctl edit getty@tty1 and then add the following snippet between the indicated comment lines in the file.

In my case, there was a line that said Anything between here and the comment below will become the new contents of the file. Paste the snippet there.

ExecStart=-/sbin/agetty --autologin joe --noclear %I 38400 linux

Remember to replace joe with the username that you'd want to use for autologin.

GRUB timeout

This step is optional. If you dont want to see the GRUB boot screen everytime your computer boots up, open up /etc/default/grub as root and then change the value of GRUB_TIMEOUT to something less than 5. I have it set to 1.


Then proceed to apply the change with

sudo update-grub

Reboot and enjoy!. If you've put 0 for the timeout, pressing the Shift key(for BIOS) or Esc key(for UEFI) when the system boots will bring up the GRUB menu.

Happy Hacking & have a great day!