Linux: Auto Login without XDM

Beware that the following contains a severe security issue if not well used.

A tiny command in C

source code

int main()
{
    execlp("login","login","-f","YOUR LOGIN HERE",0);
}

compilation

Just use gcc :

    gcc -o autologin autologin.c

Usage

First, Copy the compiled command to /usr/sbin. Then, edit you inittab file (eg. /etc/inittab) and modify to have line like the following :

    1:2345:respawn:/sbin/getty -n -l /usr/sbin/autologin 38400 tty1

You can always log-in as a different user by using another virtual term or any ssh connection.

Extras

Now that your user is automatically logged in, you can execute any command after you have been logged using your bash profile. For exemple adding the following in you ~/bash_profile will automatically log you in if current tty is tty1:

if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
    startx
fi

This will automaticaly launch X when the current used tty is /dev/tty1

Questions or comments?

Join the discussion on Discord, ask a question or share your experience.

Discuss on Discord
  1. ChatGPT Image Jan 30, 2026, 07_13_27 PMXMG Pro 16 m25 under Linux: Maximum GPU Power and Gaming Performance
  2. 20250128_224935Cloud at home with minimum toil - PXE / Proxmox / Saltstack / k3s
  3. Banana Pi M1 single-board computerAnother NAS with a BananaPI