Wednesday, October 30, 2013

Linux Automatic Login At Command Line

Since I'm about to build a tiny little media player with the Raspberry PI, I thought I'd write myself some notes to remind me of some set up features that I might require.  Creating an automated log on for the GUI is fairly straight forward as the generally relies on messing around with the GDM files.

It turns out it is also easy for the command line too.

/etc/init/tty.conf is used to control what happens with console log on.

The line;
exec /sbin/mingetty $TTY
Is the default line that tells the getty process to perform the log on prompt. You can change this to suit your needs, so if you wanted root to log on you could do;

exec /sbin/mingetty --autologin root $TTY

This will log the system in as root at a command prompt.

Other options to mingetty;
--loginprog=/sbin/someprogram
--chdir=/somedirectory
--chroot=/jaildirectory

man mingetty will tell you the rest

For systemd based versions you need to do the following;
Change to the /etc/systemd/system folder.
If you need more terminals then do the following;
cp /lib/systemd/system/getty@.service /etc/systemd/system/autologin@.service
ln -sf /etc/systemd/system/autologin@.service  /etc/systemd/system/getty.target.wants/getty@tty1.service

In the file getty.target.wants/getty@tty1.service change the following;
ExecStart=-/sbin/agetty --autologin root %I

Obviously substitute root for your specific user.