Automatic login to virtual console

From ArchWiki

Jump to: navigation, search
Article summary
Covers the various methods one can use to automatically login to a virtual console during the boot process.
Available in languages
English
Related articles
Start X at boot
Automatic login manager startup

This article covers how one can automatically login to a virtual console during the boot process. If utilizing a display manager, please note that most display managers provide some automatic login mechanism; separate from what is described here. See each display managers' documentation for specific details.

Additionally, see Start X at boot#/etc/inittab for a method describing how to automatically login to an X session. This article only describes how to achieve a console login; methods for starting an X server are described elsewhere.

Using mingetty

This is the preferred (i.e. clean) method.

Install the mingetty package from the AUR. mingetty is designed to be a minimal getty and allows automatic logins. Then, in etc/inittab change:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

to

c1:2345:respawn:/sbin/mingetty --autologin USERNAME tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

The user can change every line to use mingetty if preferred; but this is unnecessary.

Using a C login program

As an alternative, a C login program can be written:

File: autologin.c
#include <unistd.h>

int main() {
   execlp( "login", "login", "-f", "USERNAME", 0);
}

Here, the C function execlp executes the command login -f USERNAME.

The program must be compiled and copied to an appropriate location:

# gcc -o autologin autologin.c
# cp autologin /usr/local/sbin/

Finally, edit etc/inittab and change:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

to:

c1:2345:respawn:/sbin/agetty -n -l /usr/local/sbin/autologin 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux
Personal tools