By default, the root user account password is locked in Ubuntu Linux for security reasons. As a result, you can not login using root user or use a command such as ‘su -‘ to become a SuperUser.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Ubuntu |
Time | 1m |
You need to use the passwd command to change the password for user accounts on Ubuntu Linux. A typical user can only change the password for his/her account only. A SuperUser (root) can change the password for any user account. Your user account info stored in /etc/passswd and an encrypted password stored in /etc/shadow file.
How to change root password in Ubuntu
The procedure to change the root user password on Ubuntu Linux:
- Type the following command to become root user and issue passwd:
sudo -i
passwd - OR set a password for root user in a single go:
sudo passwd root - Test it your root password by typing the following command:
su -
How to disable your root account on Ubuntu
One can disable the root account by typing the following command:
$ sudo passwd -dl root
OR
$ sudo passwd --delete --lock root
Sample session from the above commands:
Understanding passwd command option
- -d OR --delete : Delete a user’s password (make it empty for root user). This is a quick way to disable a password for an account. It will set the named account passwordless.
- -l OR --lock: Lock the password of the named account such as root. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ‘!’ at the beginning of the password)
- root : Lock and disble root account i.e. re-disabling your root account
A note about root password on an Ubuntu server/desktop
Enabling the root account by setting the password is not needed. Almost everything you need to do as SuperUser (root) of an Ubuntu server can be done using sudo command. For example, restart apache server:
$ sudo systemctl restart apache2
You can add additional user to sudo by typing the following command:
$ sudo adduser {userNameHere} sudo
For example, add a user named tom to sudo:
$ sudo adduser tom sudo
You can in as another user say logging as tom from jerry account:
{jerry@nixcraft}$ sudo -i -u tom
When prompted enter jerry’s password i.e. the password being asked for is your own, not tom’s. For more info see “How to create a new sudo user on Ubuntu Linux server” and RootSudo.
- Linux Login as Superuser ( root user )
- How can I log in as root?
- How do I become superuser on Ubuntu Linux using su/sudo?
- Ubuntu Linux root Password (Default Password)
- How to create a new sudo user on Ubuntu Linux server
- How to change root password on RHEL ( Red Hat Enterprise Linux)
- How to change root password on CentOS Linux
- How to change root password on Alpine Linux
- How to change root password on SUSE / OpenSUSE Linux
- Change the Password in UNIX
- How to change root password on Debian Linux
- How to change root password on Fedora Linux
- How to change root password on macOS Unix
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Pretty simple:
sudo passwd root
Type YOUR OWN password tho.