Enable and Disable Root User Account on Ubuntu 20.04

Enable and Disable Root User Account on Ubuntu 20.04 Техника

Note: For help with configuring sudo privileges via its configuration file /etc/sudoers, please see Sudoers.

Run the command mentioned below to enable the account:

$ sudo -i

The password can then be updated using either the «sudo passwd root» or «» command.

$ sudo -s

$ sudo su —

$ sudo — root

After enabling the account using the above command, the password can be updated using either the «sudo passwd root» or «» command.

We can help you

Updated: by

Enable and Disable Root User Account on Ubuntu 20.04

Logging in as root

Or, you can use the whoami command to determine the account you are using.

When logging in as root, it is often useful to use a single dash after the su command, like this:

Running commands as root without the root password

Using sudo makes it difficult to forget you’re root since you’re not logged in to the root account, and are never going to forget to log out. Also, typing sudo every time you run a potentially destructive command reminds you to be extra careful and double check yourself.

Here at , as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.

Run the below command:

$ sudo passwd root

OutputEnter new UNIX password:Retype new UNIX password:passwd: password updated successfully

It’s strongly recommend that you set strong and unique password. It is a most important security aspect of your system. Your password should have at least 14 characters and contains one uppercase letter, one lowercase letter, one number, and one special character.

Finally, you have successfully enabled the root account by setting up password.

$ sudo passwd -l root

This guide will help you out.

Su command.

The syntax is:

$ su —

You will get an output such as;

Дополнительно:  0x000000d1: код STOP-ошибки в Windows 7, 10 и XP, как исправить этот синий экран смерти (BSoD), проблема с файлами ndis и srvnet sys

$ su — linuxapt

You will get an output such as this;

How to establish Remote root login over the ssh session?

## now switch to root account ##

More about su command and log files?

tail -f /var/log/secure

tail -f /var/log/auth.log

More about sudo command?

For instance, to login as root under Linux, execute the command:

Then your will be prompted to enter a password. Once you enter the password, you will be logged in as the root and you will be able to enjoy sudo privileges.

How to work with Sudo and log file?

## Generic file for Unix/Linux ##

tail -f /var/log/messages

## Debian/Ubuntu ##

## RHEL/CentOS/SL/Fedora Linux ##

Думаете, с вами такого не случится? Даже опытные администраторы Linux рассказывают жуткие истории о том дне, когда они сделали роковую опечатку или не задумывались над тем, что они делают, работая под именем суперпользователя.

По умолчанию учетная запись суперпользователя отключена в Ubuntu. Это означает, что вы не сможете зайти в систему как root. Однако, инсталлятор настраивает sudo для пользователя, созданного во время установки. Команда sudo позволяет выполнять все приложения, требующие привилегий суперпользователя.

Когда sudo спрашивает пароль, вы должны ввести пароль ВАШЕГО пользователя ! То есть пароль root’a вам не нужен !

Root User in Ubuntu GUI

The first step to log in as root in Ubuntu is using the root credentials to edit the custom.conf file. For this step, first set the password as shown below:

The output should look something like this:

Enable and Disable Root User Account on Ubuntu 20.04

Type the password for the root account and hit the “Enter” key. However, you can skip this step if the root already has a password.

Activate the Root Account

After that, enable the lightdm, gdm, or kdm mode for the root account.

Once the account is active, we’ll edit the custom.conf located at /etc/gdm3/. Since it is a system file, we’ll create the backup first using the cp command. Specifically, type:

cp /etc/gdm3/custom.conf /etc/gdm3/custom.conf~

After that, open the custom.conf file using your favorite text editor. For instance, type:

# nano text editor
sudo nano /etc/gdm3/custom.conf
# vim text editor
sudo vim /etc/gdm3/custom.conf

Enable and Disable Root User Account on Ubuntu 20.04

Hit the “Enter” key to exit the vim editor.

KDM Ubuntu

In the KDM Ubuntu mode, edit the /etc/sddm.conf. However, if the file isn’t available, you can create it using the touch, nano, or vim commands. For instance, type:

# touch command
sudo touch /etc/sddm.conf.d/uid.conf
# nano editor
sudo nano /etc/sddm.conf.d/uid.conf
# vim editor
sudo vim /etc/sddm.conf.d/uid.conf

Enable and Disable Root User Account on Ubuntu 20.04

Make sure to reboot the system to implement the changes. For this step, execute the reboot command as shown below:

Дополнительно:  Что делать, если пропал звук на ноутбуке?

LightDM Ubuntu

# nano editor
sudo nano /etc/lightdm/lightdm.conf
# vim editor
sudo vim /etc/lightdm/lightdm.conf

Next, add the line given below:

Lastly, reboot the system using the reboot command. For example, type:

After that, we will edit the PAM authentication daemon configuration file. This file is located at /etc/pam.d/gdm-password. Open this file as well using your favorite text editor. For instance, type:

# nano text editor
sudo nano /etc/pam.d/gdm-password
# vim text editor
sudo vim /etc/pam.d/gdm-password

This statement denies access to the Ubuntu GUI. to comment, add the pound “#” operator as shown below:

Save your file and exit the text editor.

Reboot the Ubuntu GUI

Once the changes are done, reboot the system using the reboot command. For example:

Disable Root Login in Ubuntu GUI

To revert the root account access, you can disable the root log in in Ubuntu GUI. for this step, use the passwd command. Specifically, type:

sudo passwd -dl root

This will revert the changes that you’ve made to enable the root login on Ubuntu GUI.

And that’s all for this guide. Here, we looked at how you can enable log in as root in Ubuntu GUI. This should work for the GNOME desktop environment. However, it is not recommended to enable the root login as you can achieve all root-level tasks with the sudo command. But if you enabled it, make sure to disable it once you’re done.

Special notes on sudo and shells

None of the methods below are suggested or supported by the designers of Ubuntu.

To start a root shell (i.e. a command window where you can run root commands), starting root’s environment and login scripts, use:

sudo -i (similar to sudo su — , gives you roots environment configuration)

To start a root shell, but keep the current shell’s environment, use:

sudo -s (similar to sudo su)

Summary of the differences found —

For a detailed description of the differences see man su and man sudo .

Заблуждения

To enable the root account (i.e. set a password) use:

Use at your own risk!

Re-disabling your root account

Не рекомендуется это делать!

Consider using the below command instead:

Использование этой команды временно откроет консоль с правами root. Активация аккаунта root в Ubuntu не поддерживается из-за ненадобности. Всё, что вам требуется сделать с правами администратора в Ubuntu можно сделать через sudo или gksudo.

Если root включен, и вы хотите отключить его, откройте терминал и введите следующую команду:

Logging in as another user

sudo -i -u amanda

Дополнительно:  Решение ошибки PAGE FAULT IN NONPAGED AREA Windows 10

The password being asked for is your own, not amanda’s.

Заметки

Пример #1 — смена пользователя и группы для файлов в домашней папке пользователя

sudo chown bob:bob /home/bob/*

Пример #2 — перезапуск сетевых служб

sudo /etc/init.d/networking restart

sudo -i (эквивалент команды «sudo su -«)

sudo -s (эквивалент команды «sudo su»)

Remove Password Prompt For sudo

These instructions are to remove the prompt for a password when using the sudo command. The sudo command will still need to be used for root access though.

Edit the sudoers file

michael ALL=NOPASSWD: ALL

Type in ^x to exit. This should prompt for an option to save the file, type in Y to save.

Log out, and then log back in. This should now allow you to run the sudo command without being prompted for a password.

Or to do this for the system wide group sudo

Log out, and then back in.

Drag & Drop Sudo

Этот трюк взят из форумов.

Создайте кнопку запуска со следующей командой:

gksudo «gnome-open %u»

Теперь при перетаскивании любого файла на эту кнопку, будет запущено ассоциированное с этим файлом приложение с привилегиями суперпользователя. Это особенно удобно при редактировании конфигурационных файлов.

Benefits of using sudo

There are a number of benefits to Ubuntu leaving root logins disabled by default, including:

Graphical sudo

Please note that many websites and old threads advise the use of gksu. However, such search results are obsolete. gksudo has not been updated for years and is not even available in Bionic (18.04) and higher. gksu has been replaced by pkexec, but even pkexec is being deprecated by the mainline Ubuntu developers. They have taken the position that file manipulation and editing under root should be restricted to the command line.

Flavour-specific workarounds

There are a number of flavour-specific options for running graphical applications as root:

General workarounds

To use sudo on the command line, preface the command with sudo, as below: Example #1

To repeat the last command entered, except with sudo prepended to it, run:

Downsides of using sudo

Although for desktops the benefits of using sudo are great, there are possible issues which need to be noted:

Allowing other users to run sudo

In the terminal (for Precise Pangolin, 12.04), this would be:

In previous version of Ubuntu

Преимущества использования sudo

Причины, по которым пользователь root отключен по умолчанию, заключаются в следующем:

Reset sudo timeout

You can make sure sudo asks for password next time by running:

Other Resources

CategoryCommandLine CategorySecurity CategoryCommandLine

Оцените статью
Master Hi-technology
Добавить комментарий