How to automatically login user at the console

Whenever I see auto-login feature implemented by using X login manager, I immediately think about how to automatically login user at the console without even touching graphical user interface.

Solution is so simple that I will not elaborate, but immediately move on to the point.

Inspect the /etc/inittab file.

$ cat /etc/inittab  | grep tty.$
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6

To automatically login milosz user at the the tty3 and tty4 terminals you need to use -a parameter for getty command (agetty to be precise) to specify username that will be logged in without asking for login name and password.

You can also use -i parameter to suppress display of the issue file and -p parameter to wait for any key before dropping to the shell.
$ sudo vi /etc/inittab 
[...]
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty -a milosz 38400 tty3
4:23:respawn:/sbin/getty -a milosz -i -p 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6
[...]
To suppress displaying motd file, comment out pam_motd PAM module in the /etc/pam.d/login configuration file.

Changes will take effect after system reboot, but it is not necessary to do it as you can just execute the following commands.

Re-read inittab configuration file.

$ sudo telinit q

Take note of the PIDs of the getty processes listening on the tty3 and tty4 terminals and then simply kill them.

$ ps ax | grep getty.*tty[3-4]
 4308 tty3     Ss+    0:00 /sbin/getty 38400 tty3
 4309 tty4     Ss+    0:00 /sbin/getty 38400 tty4
$ sudo kill 4308 4309

Now you will be automatically logged in whenever you switch to the tty3 or tty4 console.

Please read systemd solution for recent operating systems.

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.