Selasa, 05 Maret 2024

AUTOLOGIN-ubuntu22.04

 

How to Setup/Enable Automatic Login on Ubuntu 22.04

https://linuxgenie.net/setup-automatic-login-ubuntu-22-04/

Ubuntu 22.04 comes with a command line as well as GUI support. Thus, you have two ways to set up an automatic login on Ubuntu 22.04:

Using the Command Line

The login screen will be configured to accept the automatic login (without asking for the password). Follow the steps to enable/set the automatic login on Ubuntu 22.04:

Step 1: Identify the Display Manager

First, check the display manager of your system (if not known). Here are the two possible commands:

cat /etc/X11/default-display-manager
sudo systemctl status display-manager

The output of both commands shows that the GNOME Display Manager is the display manager being used.

Step 2: Configure the Display Manager for Automatic Log in

The configuration file of the GNOME display manager is available in “/etc/gdm3/custom.conf”. In your case, the display manager could be different. Some of the most used display manager (sddm and lightdm) has the configuration files at:

/etc/lightdm/lightdm.conf.d/lightdm.conf
/etc/sddm.conf

Let’s open the GNOME DM:

sudo nano /etc/gdm3/custom.con

Open the configuration file and uncomment the lines starting with the “AutomaticLoginEnable” and “AutomaticLogin”. Uncomment these parameters and ensure the correct values are set, i.e., true for the first parameter and the username in the second parameter.

Save and exit out of the editor. Reboot the system and you will be logged into the system with the configured user (set in the display manager’s config file, i.e., adnan in our case).

Note: if you are using the sddm or lighdm as a display manager, these parameter names will vary.

Using the GUI

Open the GNOME settings and:

  • Click on the user for which you want to enable the automatic login feature.
  • Click on the Unlock button to enter the edit mode.

Enter the user password and you will be inside the edit mode.

Now, scroll down to get inside the “Authentication & Login”. Turn ON the toggle button of “Automatic Login”:

The automatic login is enabled for this user now.

How to Disable Automatic Login on Ubuntu 22.04

To disable the automatic login, you have the same ways that you followed to enable the automatic login. Let’s quickly go through this:

Command Line

Open the configuration file of the display manager (Step 1) and trace the automatic login lines. Comment all these lines, as we did here:

The automatic login will be disabled for the user, i.e., adnan.

GUI

Open the Users section in the GNOME settings. Navigate to the user (to turn off the automatic login) and Turn Off the toggle button in front of the Automatic login option:

How to Enable/Disable the Timed Login on Ubuntu 22.04

What if you want to set the timer that after 30 seconds the system should automatically log into? You can easily do it by modifying the “TimedLogin” related parameters of your display manager.

Here is the process:

Step 1: Modify the Configuration File

Open the configuration file of your display manager and look for the “Enabling timed login” section, highlighted below. Here:

  • Uncomment all the lines associated with the timed login.
  • Set the username for which these settings will be valid.
  • Set the waiting time in seconds (after that the user will be logged in automatically).

Note: At the time of disabling, you need to comment on all the above parameters.

Step 2: Reboot the System

Reboot your system and you will notice that the login screen appears only for 10 seconds (or whatever time you set) and then instantly logs in the set user. A progress bar appears under the username (that is set for timed login), which ends after the set logged-in time.

Note: To disable the timedlogin feature, open the display manager’s configuration file and comment all the timedlogin-related lines.

Bonus: How to Setup Automatic Login on the Ubuntu Server

Enabling the automatic login process on the Ubuntu server is a bit different from the Ubuntu desktop. Ubuntu server uses the tty terminals which are managed by Ubuntu itself (unlike the Ubuntu desktop where some display manager is the key component to configure). Let’s practice how you can setup automatic login on the Ubuntu server:

Step 1: Configure the Login Settings for TTYs

Open the login-related configuration file on the Ubuntu server. Here actually, we will set up the automatic login of the virtual terminals (TTYs) that appear right after starting the Ubuntu server:

sudo nano /etc/systemd/logind.conf
  • NAutoVTs: The terminal range up to which the automatic login will work.
  • ReserverVT: the terminal number from where the automatic login will not work.

Step 2: Configure the systemd Service for TTYs

Create a directory for the service (getty is used to refer the tty terminals for login):

sudo mkdir /etc/systemd/system/getty@tty1.service.d/

Create a service file. We are only configuring the tty1, for other ttys, use the respective name, i.e., “getty@tty2.service.d” for tty2 and so on:

sudo nano /etc/systemd/system/getty@tty1.service.d/override.conf

Use the following lines in the service file:

[Service]
ExecStart=
ExecStart=-/sbin/agetty --noissue --autologin adnan %I $TERM
Type=idle
  • ExecStart=-/sbin/agetty: When the service is started the “/sbin/agetty” command will be executed.
  • –noissue: With this flag, the agetty neither prints the welcome nor any error message.
  • –autologin: Enable the automatic login for the username, i.e., adnan. Replace it with your own.
  • %I: It gets replaced with the specific terminal’s instance (tty1, tty2, tty3, etc) where the agetty is running.
  • $TERM: This is an environment variable referring to the terminal type.

In short, the “getty” is configured to automatically log in the user “adnan” on the specific terminal, i.e., tty1 in this case. Whereas the %I and $TERM optimize the overall process.

Reboot the Ubuntu server and you will see the automatic login appear on the tty1, i.e., the default terminal of the Ubuntu server.

That’s how you can enable/set up automatic login on Ubuntu Desktop and Server.

Bottom Line

To enable/set up the automatic login feature on Ubuntu 22.04, you have to modify the configuration file of the display manager. Moreover, you can also set up the Automatic login from the Users section in the GNOME settings. Similarly, to disable the automatic login, you need to revert all the changes you made via CLI and GUI.

Today, you have learned to set up/enable automatic login on Ubuntu 22.04 (Desktop and Server).

Tidak ada komentar:

Posting Komentar