How to create ubuntu server 16.04 autologin?

31,256

In Ubuntu 16.04, which uses systemd, the method is slightly different. I'll quote the relevant bits of my related post How do I override or configure systemd services?:

Say I want to have TTY2 autologin to my user (this is not advisable, but just an example). TTY2 is run by the getty@tty2 service (tty2 being an instance of the template /lib/systemd/system/getty@service). To do this, I have to modify the getty@tty2 service.

[…]

In particular, I have to change the ExecStart line, which currently is:

$ systemctl cat getty@tty2 | grep Exec     
ExecStart=-/sbin/agetty --noclear %I $TERM

To override this, do:

sudo systemctl edit getty@tty2

And add:

[Service]
ExecStart=
ExecStart=-/sbin/agetty -a <USERNAME> --noclear %I $TERM

[…]

Now:

$ systemctl cat getty@tty2 | grep Exec
ExecStart=-/sbin/agetty --noclear %I $TERM
ExecStart=
ExecStart=-/sbin/agetty -a <USERNAME> --noclear %I $TERM

And if I do:

sudo systemctl restart getty@tty2

and press CtrlAltF2, presto! I'll be logged into my account on that TTY.

Share:
31,256

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    Something has changed in server 16.04 LTS, I can't find tty1, but I need to make an auto-login on tty1 (in console mode), in 14.04 LTS I can make this work.

    I can't find /etc/init/tty1.conf

    How to, or a link?

  • Zac
    Zac about 8 years
    That procedure brings to me a blank tty screen.
  • muru
    muru about 8 years
    @Zac and what does systemctl status getty@tty2 report for you?
  • Zac
    Zac about 8 years
    I was in a virtual machine with just 1 tty, and I was not able to log in anymore! (blessed snapshots!) I solved as I wrote here.
  • muru
    muru about 8 years
    @Zac if you says so. This works fine for me on Arch Linux and Ubuntu.
  • muru
    muru over 7 years
    This answer won' t work for 16.04 because it uses systemd by default and not upstart. Even for upstart systems, you should use agetty's -a option instead of this.
  • 345422
    345422 over 7 years
    That's strange, as I was pretty sure I was running 16.04 Server. That would't change just because I was using a PPC, would it?
  • Nam G VU
    Nam G VU over 7 years
    I followed your guide and my machine can log in automatically now. BUT I cannot ssh to the machine as possible before. Please help me to get back to my SSH connection.
  • muru
    muru over 7 years
    @NamGVU since the guide doesn't touch SSH settings at all, the cause must be elsewhere. Does reverting the changes given here fix SSH?
  • VarunAgw
    VarunAgw almost 7 years
    Is there any way to automate this using a script?
  • muru
    muru almost 7 years
    @VarunAgw sure, create /etc/systemd/system/[email protected]/override.conf with the additional lines, and run systemctl daemon-reload.
  • VarunAgw
    VarunAgw over 6 years
    For some reason, tty2 doesn't auto login at reboot while tty1 does. who -u shows only tty1 after login
  • muru
    muru over 6 years
    @VarunAgw even after you switch to tty2?
  • VarunAgw
    VarunAgw over 6 years
    @muru I can't switch using Ctrl+Alt+F2. I have develop a program which use ttyecho to launch a program in tty2 and then take regular screenshots using fbgrab
  • Tomilov Anatoliy
    Tomilov Anatoliy over 6 years
    How to revert these changes?
  • muru
    muru over 6 years
    @Orient delete the override file in /etc/systemd/system/getty*.service.d
  • Tomilov Anatoliy
    Tomilov Anatoliy over 6 years
    @muru Can I just edit /etc/systemd/system/getty.target.wants/[email protected] instead of systemctl edit getty@tty1?
  • muru
    muru over 6 years
    @Orient the usual method to manually do this is to create .conf files /etc/systemd/system/[email protected]/ and run systemctl daemon-reload. I'm not so sure of using other directories.