How can I get autologin at startup working on Ubuntu Server 16.04.1?
Solution 1
Try this:
sudo systemctl edit [email protected]
This will the create a drop-in file (if neccessary) and open it an editor. Add the following, replacing myusername
with your user name:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin myusername %I $TERM
Type=idle
This will:
- Create the folder
/etc/systemd/system/[email protected]
if necessary - Create the file
/etc/systemd/system/[email protected]/override.conf
if necessary
Solution 2
agetty opens a tty port, prompts for a login name and invokes the /bin/login
command.
This file overrides the config by default of agetty on systemd for tty1. This provides a new instance of tty1 with autologin for the user specified.
By the way, the parameter --noissue
is used to hide the contents of /etc/issue
on login, so not needed in your case.
The option Type=idle
found in the default [email protected]
will delay the service startup until all jobs are completed in order to avoid polluting the login prompt with boot-up messages. When starting X automatically, it may be useful to start [email protected]
immediately by adding Type=simple
into the file.
More info: getty: Archlinux.org
Related videos on Youtube
Tomek
Updated on September 18, 2022Comments
-
Tomek over 1 year
I have a problem with autologin at startup in Ubuntu Server 16.04.1 LTS.
I use this server only for listening internet radio so I do not care about security.
I was able to create a bash script to auto start mplayer but can't configure autologin.
I've tried at least 4 solutions (always editing the file
/etc/init/tty1.conf
and of course replacing USERNAME with actual user name):change the line from
exec /sbin/getty -8 38400 tty1
to
exec /sbin/getty -8 38400 tty1 -a USERNAME
change the line from
exec /sbin/getty -8 38400 tty1
to
exec /bin/login -f USERNAME < /dev/tty1 > /dev/tty1 2>&1
Install
rungetty
, comment the lineexec /sbin/getty -8 38400 tty1
and add the line
exec /sbin/rungetty --autologin USERNAME tty1
Install
mingetty
, comment the lineexec /sbin/getty -8 38400 tty1
and add the line
exec /sbin/mingetty --autologin USERNAME tty1
Nothing helps - I have to input my login and password at startup - any ideas what to do?
-
Tomek over 7 yearsOnce again - thank you very much for explanations - they are very deep and clear. Some more information about autologin here: askubuntu.com/questions/771837/… and about overriding here: askubuntu.com/questions/659267/…
-
Nam G VU about 7 yearsI followed your guide and my machine can log in automatically now. BUT I cannot ssh to the machine as possible before. Please help me to get back to my SSH connection.
-
Jose Carlos Nieto Ramos about 7 yearsHi Nam. Your user have a password? I tried this in a machine and i can access to it over SSH with the user passwd. Shows any error? Thanks.
-
Nam G VU about 7 yearsToo long ago and the machine is deleted on my side; sorry I can't get you the error. User has a password of course.
-
Patrizio Bertoni over 6 yearsYour guide took me stuck at
[OK] Started Update UTMP about System Runlevel Changes.
during boot -
PerlDuck almost 6 yearsInstead of manually creating the
.d
directory and theoverride.conf
file we can also simply saysudo systemctl edit [email protected]
. It will the create the file (if neccessary) and open it an editor. Simply save the file under the suggested name when finished. -
kleash about 4 yearsThanks for the answer, my autologin is also working now. May I know do you have anyway to wait for 10sec before autologin so that anyone can interrupt autologin between that period and login manually with different user.
-
tresf about 4 yearsStill works in 20.04. @PerlDuck I've edited the solution with a request that your improved steps are added to the original solution, they're faster, use the official
systemctl
tool which is less prone to error and chooses a text editor automatically, alleviating doubt. I've preserved the OP's documentation about the files that it creates so it doesn't lose informational value. Thanks kindly! -
PerlDuck about 4 years@tresf Very nice, thank you. I took the freedom to replace "This will the create the file" with "This will the create a drop-in file" so that people know what kind of file that is -- and what to search for in case more information is needed.
-
John Smith almost 4 yearsDoesn't work in 20.04. (as appears to be the standard for Ubuntu questions.) Rebooting the machine after these steps, I ran "who", and the user was not logged in.
-
Onkeltem over 3 yearsDoesn't work on 18.04. I just get a black screen with blinking cursor...
-
TabsNotSpaces about 3 yearsWorked like a charm in ubuntu server 20.04.2 fresh install. Ran
sudo systemctl edit [email protected]
and added the file contents then rebooted. On reboot, the user had logged in.