6

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?

muru
  • 197,895
  • 55
  • 485
  • 740
  • I have the /etc/init/tty[1-6].conf after an upgrade from 14.04... Did you do a fresh install? I could be that you somehow switched to full X11 (graphical) only mode. – Alexis Wilke May 23 '16 at 02:09
  • See this for classic inittab login: https://unix.stackexchange.com/questions/299408/how-to-login-automatically-without-typing-the-root-username-or-password-in-build/300152#300152 – Ciro Santilli OurBigBook.com Oct 11 '18 at 07:08

2 Answers2

11

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.

muru
  • 197,895
  • 55
  • 485
  • 740
  • That procedure brings to me a blank tty screen. – Zac Jun 14 '16 at 08:10
  • @Zac and what does systemctl status getty@tty2 report for you? – muru Jun 14 '16 at 08:14
  • 1
    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. – Zac Jun 14 '16 at 08:17
  • 1
    @Zac if you says so. This works fine for me on Arch Linux and Ubuntu. – muru Jun 14 '16 at 08:18
  • 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. – Nam G VU Feb 10 '17 at 10:15
  • @NamGVU since the guide doesn't touch SSH settings at all, the cause must be elsewhere. Does reverting the changes given here fix SSH? – muru Feb 10 '17 at 10:16
  • Is there any way to automate this using a script? –  Sep 19 '17 at 11:14
  • 2
    @VarunAgw sure, create /etc/systemd/system/getty@tty2.service.d/override.conf with the additional lines, and run systemctl daemon-reload. – muru Sep 19 '17 at 11:37
  • For some reason, tty2 doesn't auto login at reboot while tty1 does. who -u shows only tty1 after login –  Oct 09 '17 at 00:45
  • @VarunAgw even after you switch to tty2? – muru Oct 09 '17 at 00:47
  • @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 –  Oct 09 '17 at 12:57
  • How to revert these changes? – Tomilov Anatoliy Nov 13 '17 at 11:33
  • @Orient delete the override file in /etc/systemd/system/getty*.service.d – muru Nov 13 '17 at 11:35
  • @muru Can I just edit /etc/systemd/system/getty.target.wants/getty@tty1.service instead of systemctl edit getty@tty1? – Tomilov Anatoliy Nov 13 '17 at 11:37
  • @Orient the usual method to manually do this is to create .conf files /etc/systemd/system/getty@tty2.service.d/ and run systemctl daemon-reload. I'm not so sure of using other directories. – muru Nov 13 '17 at 11:40
-2

I used this website to achieve auto-login: http://www.pcworld.com/article/259236/how_to_turn_your_laptop_into_a_typewriter.html.

sudo nano /etc/init/tty1.conf

Again, type your password if requested. You are now editing a configuration file, the last line of which starts with an 'exec' command. Replace that line with:

exec /bin/login -f USERNAME < /dev/tty1 > /dev/tty1 2>&1

Where USERNAME is your own username, of course. Be sure to type this line accurately. Then save the file (Ctrl+O) and exit (Ctrl+X).

Now, let's test again to make sure everything is working correctly. Reboot the computer to see if automatic login works:

sudo reboot now
George Udosen
  • 36,677
345422
  • 199
  • 1
    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. – muru Jan 23 '17 at 12:41
  • 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? – 345422 Jan 23 '17 at 13:20