Automatic login to virtual console
From ArchWiki
| Summary |
|---|
| Describes how to automatically login to a virtual console. |
| Related |
| Display Manager |
| Start X at boot |
This article describes how to automatically login to a virtual console at the end of the boot process. This article only covers console logins; methods for starting an X server are described in Start X at boot.
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 it is not necessary.
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