Automatic login to virtual console - ParabolaWiki

# Automatic login to virtual console

Summary
Describes how to automatically log in to a virtual console.
Related
Display Manager
Start X at Boot

This article describes how to automatically log in to a virtual console at the end of the boot process. This article only covers console log-ins; methods for starting an X server are described in Start X at Boot.

## Using agetty or mingetty

Note: Although it is a mingetty derivative, fgetty does not support the --autologin parameter

This is the preferred (i.e. clean) method. Edit /etc/inittab:

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

and change it to:

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

to automatically log in USERNAME to the first console (tty1).

Alternatively, you can install the mingetty package from the official repositories. mingetty is designed to be a minimal getty and allows automatic log-ins. Then, change the default /etc/inittab to:

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

Using the above ways, you will not be able to log out from tty1, it will log you back again over and over. If you want the automatic login process to happen only at boot, and to be able to log out, you can edit /etc/inittab like this:

Note: This way, you will not be able to access the other virtual consoles until after you log out.

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

## Using a C login program

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

    autologin.c

    #include <unistd.h>

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

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 -s 38400 tty1 linux
    c2:2345:respawn:/sbin/agetty -8 -s 38400 tty2 linux
    c3:2345:respawn:/sbin/agetty -8 -s 38400 tty3 linux
    c4:2345:respawn:/sbin/agetty -8 -s 38400 tty4 linux
    c5:2345:respawn:/sbin/agetty -8 -s 38400 tty5 linux
    c6:2345:respawn:/sbin/agetty -8 -s 38400 tty6 linux

to:

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

## Acknowledgement

This wiki article is based on ArchWiki. We may have removed non-FSDG bits from it.
Categories:

- Boot process
- Security
- Request:Correction