Ubuntu 21.04
Sponsored Link

Initial Settings : Enable root User Account2021/04/28

 
The root Account in Ubuntu is disabled by default because his password is not set. To use root priviledges, basically it's better to use the sudo command with administrative accounts. But if you'd like to use root Account itself by some reason, it's possible to use like follows.
[1] The user account added during installation is set an administrative account with Sudo, so it's easy to get root account's shell like follows.
ubuntu@localhost:~$
sudo -s

[sudo] password for ubuntu:   # input self password
root@localhost:/home/ubuntu#  # just switched
[2] Or it's possible to switch to root account with standard su command to set root account's password.
ubuntu@localhost:~$
sudo passwd root

[sudo] password for ubuntu:   # input self password
New password:                 # set root password
Retype new password:          # confirm
passwd: password updated successfully

ubuntu@localhost:~$
su -

Password:                     # input root password
root@localhost:~#             # just switched
*
The examples on this site shows by root user account. If you use Sudo, add [sudo] on the head of commands.
It's better to restrict users who can [su] to root if you enable root account like follows. For using by Sudo, it's possible to limit to prohibit shells in sudoers config, refer to details about Sudo Settings.
[3] For [su] command restriction, set like follows.
root@localhost:~#
vi /etc/pam.d/su
# line 15 : uncomment and add a group which is allow to run [su] command

auth       required   pam_wheel.so  group=adm

# add a user you allowed to run [su] to the group you set above

root@localhost:~#
usermod -aG adm ubuntu

Matched Content