Automatically login some user to a virtual console on startup

From ArchWiki

Jump to: navigation, search


[edit] Using mingetty to log in users

Preferred method: You can use the mingetty package, that is available from the Arch User Repository. In /etc/inittab change:

c1:2345:respawn:/sbin/agetty 38400 vc/1 linux
c2:2345:respawn:/sbin/agetty 38400 vc/2 linux
c3:2345:respawn:/sbin/agetty 38400 vc/3 linux
c4:2345:respawn:/sbin/agetty 38400 vc/4 linux
c5:2345:respawn:/sbin/agetty 38400 vc/5 linux
c6:2345:respawn:/sbin/agetty 38400 vc/6 linux

to

c1:2345:respawn:/sbin/mingetty --autologin george vc/1 linux
c2:2345:respawn:/sbin/agetty 38400 vc/2 linux
c3:2345:respawn:/sbin/agetty 38400 vc/3 linux
c4:2345:respawn:/sbin/agetty 38400 vc/4 linux
c5:2345:respawn:/sbin/agetty 38400 vc/5 linux
c6:2345:respawn:/sbin/agetty 38400 vc/6 linux

you can change every line to use mingetty if you prefer however that's not necessary.

[edit] Using a C login program

As an alternative you can:

  • Create a C login program, autologingeorge.c, for the user george:
#include <unistd.h>

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

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

  • Compile it:
# gcc -o autologingeorge autologingeorge.c
  • Gain root access (with su) and copy the executable to a public directory:
# cp autologingeorge /usr/local/sbin/
  • Edit /etc/inittab. The lines:
c1:2345:respawn:/sbin/agetty 38400 vc/1 linux
c2:2345:respawn:/sbin/agetty 38400 vc/2 linux
c3:2345:respawn:/sbin/agetty 38400 vc/3 linux
c4:2345:respawn:/sbin/agetty 38400 vc/4 linux
c5:2345:respawn:/sbin/agetty 38400 vc/5 linux
c6:2345:respawn:/sbin/agetty 38400 vc/6 linux

should look something like:

c1:2345:respawn:/sbin/agetty -n -l /usr/local/sbin/autologingeorge 38400 vc/1 linux
c2:2345:respawn:/sbin/agetty 38400 vc/2 linux
c3:2345:respawn:/sbin/agetty 38400 vc/3 linux
c4:2345:respawn:/sbin/agetty 38400 vc/4 linux
c5:2345:respawn:/sbin/agetty 38400 vc/5 linux
c6:2345:respawn:/sbin/agetty 38400 vc/6 linux

[edit] Restarting the system

Next time you start up your linux system, the user george will be automatically logged in on the first virtual console (vc/1). To understand why, do man agetty.

You can now Start X at boot and have your box go directly into X.

Personal tools