Automatically Login on Debian 9.2.1 Command Line
Edit your /etc/systemd/logind.conf
, change #NAutoVTs=6
to NAutoVTs=1
Create a /etc/systemd/system/[email protected]/override.conf
through ;
systemctl edit getty@tty1
Paste the following lines
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear %I 38400 linux
enable the [email protected]
then reboot
systemctl enable [email protected]
reboot
Arch linux docs :getty
I'd like to add a slightly more thorough answer, especially given the comment about breaking his system from @Keelan.
First if you wish to only have one TTY that is running the program, and not be able to log in to any other tty, THEN edit your /etc/systemd/logind.conf
, and change #NAutoVTs=6
to NAutoVTs=1
. Doing this will keep you from logging in on the terminal!
Next create a directory and an override.conf
file:
mkdir -p /etc/systemd/system/[email protected]
echo "[Service]" > /etc/systemd/system/[email protected]/override.conf
echo "ExecStart=" >> /etc/systemd/system/[email protected]/override.conf
echo "ExecStart=-/sbin/agetty --autologin root --noclear %I 38400 linux" >> /etc/systemd/system/[email protected]/override.conf
Don't reboot. Instead of rebooting, as described in the other answer, log in to another TTY, then run the following commands to test things out:
systemctl daemon-reload
systemctl restart [email protected]
If all goes well, then reboot.
But what if I want to run a program instead of autologin? Then you would use the following:
mkdir -p /etc/systemd/system/[email protected]
echo "[Service]" > /etc/systemd/system/[email protected]/override.conf
echo "ExecStart=" >> /etc/systemd/system/[email protected]/override.conf
echo "ExecStart=-/path/program -arg1 -arg2" >> /etc/systemd/system/[email protected]/override.conf
echo "StandardInput=tty" >> /etc/systemd/system/[email protected]/override.conf
echo "StandardOutput=tty" >> /etc/systemd/system/[email protected]/override.conf
Now keep in mind this will run without a bashrc
. This means if you use something like screen
then you won't get all your usual aliases/etc. To fix that, use the standard auto-login above, but add this to your .bashrc
:
[ `tty` == /dev/tty1 ] && /path/program -arg1 -arg2
This means that the program will only be run on tty1
, but will give you a full shell underneath.
I just want to add to this discussion that the accepted answer pertains to virtual terminals. In my case, I had to edit a separate service file which is used for serial terminals. The file is found at /lib/systemd/system/[email protected]
and the same procedure of adding --autologin <user>
to the appropriate line does the trick.
[Service]
ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 --autologin root %I $TERM