How to log in automatically when Ubuntu restarts

Introduction

Normally, you need to enter the login user name and password when starting and restarting Ubuntu, but here's how to automatically log in without entering the user name and password.

environment

Ubuntu 20.10

GUI (Ubuntu Desktop) If you go to "Settings"> "Details"> "Users", there is an item called "Automatic login", so turn it from off to on. You will be prompted for a password.

How to "automatically log in" to the Ubuntu 18.04 LTS desktop

CUI (Ubuntu Server) Execute the following command.

$ sudo systemctl edit [email protected]

The editor (nano) will open, so copy and paste the following.

[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin <USERNAME> %I $TERM
Type=idle

For <USERNAME>, enter the user name of the user who wants to log in automatically. You can find the current username with the whoami command.

A brief explanation of how to use nano

By the way, some people may not be familiar with nano (as well as myself), so I will explain how to save the file for the time being.

Unlike Vim, nano doesn't have normal mode or insert mode, so just copy and paste the above when the editor opens.

Then press Ctrl + X. You will be asked Save modified buffer?, So press y to save the file. When the message File Name to Write: ... is displayed, press the return key to finish.

By the way, this file seems to be open only with nano. I tried with EDITOR = vim but it opened in nano.

You should now be logged in automatically when you reboot. In the case of Ubuntu Server, I don't know if I have to connect the PC running Ubuntu Server to the monitor to check it properly.

Usefulness

It seems that a daemon that is normally started as a user will not start ** unless you log in as that user once after starting / restarting. For example, the PulseAudio daemon.

Daemons that are normally started by the user are distinguished from daemons that are started system-wide. For example, if you install PulseAudio [^ 1], there is no daemon file system wide, but a daemon file is usually provided for the user.

#Does not exist in system wide
$ systemctl status pulseaudio
Unit pulseaudio.service could not be found.
#Exists for normal users
$ systemctl --user status pulseaudio
● pulseaudio.service - Sound Service
     Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-12-20 07:46:19 UTC; 3 days ago
TriggeredBy: ● pulseaudio.socket
   Main PID: 1911 (pulseaudio)
     CGroup: /user.slice/user-1000.slice/[email protected]/pulseaudio.service
             └─1911 /usr/bin/pulseaudio --daemonize=no --log-target=journal

[^ 1]: For Ubuntu Desktop, it is installed from the beginning

Automatic login at startup is convenient when you want to automatically start these daemons at system startup / restart, not at user login.

In addition to the method introduced here, there are two possible methods when you want to automatically start such a daemon for normal users.

--How to disable a daemon for normal users and change it to start system-wide (with root privileges) --How to automatically start a daemon that originally runs with root privileges on behalf of a normal user

By the way, the second one is that it starts up like this.

ExecStart=/usr/bin/sudo -u <USERNAME> pulseaudio

I tried it with PulseAudio, but neither worked. He didn't expect PulseAudio to boot system-wide in the first place, so it didn't work [^ 2]. The method of substituting for a normal user also did not work because the daemon did not start.

[^ 2]: For the time being, the method of booting system-wide is officially explained ... Running PulseAudio as System-Wide Daemon

So, it seems safest to start the daemon for normal users as a normal user, and if you want to start the daemon automatically when the system starts, use automatic login.

Reference site

How can I get autologin at startup working on Ubuntu Server 16.04.1?

Recommended Posts

How to log in automatically when Ubuntu restarts
Ubuntu unable to log in
(Memo) How to solve dummy output in Ubuntu 20.04
How to Install Oracle JDK 1.8 in Ubuntu 18.04 LTS?
How to automatically generate a constructor in Eclipse
How to remove Ubuntu when dual booting Windows and Ubuntu
How to add HDD to Ubuntu
How to automatically generate ER diagram when migrating with Rails6
When there is no output to stdout in docker log
How to set chrony when the time shifts in CentOS7
How to use Ubuntu Server 20.10 (Groovy Gorilla) in Sakura's cloud
How to get the log when install4j does not start
How to use Lombok in Spring
How to find May'n in XPath
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to run Ant in Gradle
How to master programming in 3 months
How to learn JAVA in 7 days
How to get parameters in Spark
How to use Bio-Formats on Ubuntu 20.04
How to install Bootstrap in Ruby
Log output to file in Java
How to use InjectorHolder in OpenAM
How to install WildFly on Ubuntu 18.04
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
How to build vim on Ubuntu 20.04
How to distinguish ubuntu cloud image
How to concatenate strings in java
How to install Swiper in Rails
I can't log in to MySQL from Django when using docker-compose
How to automatically operate a screen created in Java on Windows
How to output the value when there is an array in the array
[jOOQ] How to CASE WHEN in the WHERE / AND / OR clause
How to install the language used in Ubuntu and how to build the environment
How to solve the unknown error when using slf4j in Java
How to write the view when Vue is introduced in Rails?
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
How to change app name in rails
How to get date data in Ruby
[IntelliJ IDEA] How to automatically add final when saving a Java file
How to use custom helpers in rails
How to install c2ffi on Ubuntu, which automatically parses C header files
How to reflect seeds.rb in production environment
How to use named volume in docker-compose.yml
[Rails] How to log in with a name by adding a devise name column
How to insert a video in Rails
How to standardize header footer in Thymeleaf
How to include Spring Tool in Eclipse 4.6.3?
Shortcut to automatically generate javadoc in IntelliJ
Command when dependency is broken in Ubuntu 20.04
How to add jar file in ScalaIDE