Automatic login to virtual console

From Gentoo Wiki
Jump to:navigation Jump to:search
Warning
Automatic logins pose security risks. Anyone who can start the computer can get access to the operating system. Consider a BIOS password for additional security.

Gentoo supports different init systems. Each init system requires their own solution for auto-login.
All involve passing --autologin <username> to the terminal handler called agetty, but how this is done differs per init system

Automatic login for different init systems

sysvinit

Edit /etc/inittab as follows:

FILE /etc/inittab
# TERMINALS
c1:12345:respawn:/sbin/agetty --autologin <username> --noclear 38400 tty1 linux
c2:2345:respawn:/sbin/agetty 38400 tty2 linux
c3:2345:respawn:/sbin/agetty 38400 tty3 linux
c4:2345:respawn:/sbin/agetty 38400 tty4 linux
c5:2345:respawn:/sbin/agetty 38400 tty5 linux
c6:2345:respawn:/sbin/agetty 38400 tty6 linux

openrc-init

Start with the openrc-init instructions, and adapt it for auto login on the first tty as follows:

Create a file /etc/conf.d/agetty-autologin:

FILE /etc/conf.d/agetty-autologin
agetty_options="--autologin <username> --noclear"

Replace the agetty.tty1 service with one called called agetty-autologin.tty1:

root #cd /etc/init.d
root #rc-config delete agetty.tty1
root #mv agetty.tty1 agetty-autologin.tty1
root #rc-update add agetty-autologin.tty1 default

When sys-apps/openrc is emerged with the sysv-utils USE flag enabled, /etc/init.d/agetty.tty1 will be re-added. If the flag was previously unset, it will also be re-added to the default runlevel. This can cause conflicts with the existing "-autologin" symlink when logging in to tty1.
agetty.tty1 can either be manually deleted (as file or just from the runlevel) everytime you toggle this USE flag or automtatically using /etc/portage/bashrc:

FILE /etc/portage/bashrc
post_pkg_postinst (){
if [ "${CATEGORY}/${PN}" = "sys-apps/openrc" ] && [ -f /etc/init.d/agetty.tty1 ] && [ -f /etc/init.d/agetty-autologin.tty1 ]; then
rm /etc/init.d/agetty.tty1
fi
}

This hook will be run on every emerge. It checks if the package is openrc, if the undesired agetty.tty1 was reinstalled, and the autologin symlink is present (otherwise you would be left without a tty1). If all this is true, it is safe and desired to remove agetty.tty1.

systemd

FILE /etc/systemd/system/getty@tty1.service.d/override.conf
[Service]
Type=simple
ExecStart=
ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux

Continue with starting an X session

This is described at X without Display Manager.