linux commands

How to set or change root password in Ubuntu Linux ?

This tutorial guides you on how to set or change root password in Ubuntu Linux. If you are new user and have access to shell and wanted to set or change root password then you are at the right place.

How to set or change root password in Ubuntu Linux

By default, the root user account password is not set or locked in Ubuntu. In order to login as root user or use command “su –” i.e., to become super user execute the below commands.

Note, I have tried set up or change root password for a ubuntu linux VM machine on Google Cloud. But, these commands are same and you can execute them in your local machine also.

First, you can type the following command to become root user and issue passwd

Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to sneppets-300712.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.

$ sudo -i

$ passwd
New password: 
Retype new password:

Or else, you can also set password for root user by using the following command in single line.

$ sudo passwd root

New password:
Retype new password:
passwd: password updated successfully

To test root password that is set or updated successfully, execute the following command.

$ su -

Password:
Welcome to Cloud Shell! Type "help" to get started.
To set your Cloud Platform project in this session use “gcloud config set project [PROJECT_ID]”

root@cloudshell:~$

Finally, execute the following command if you wanted to logout or exit ( as root user).

root@cloudshell:~$ exit

logout

Enable SSH password authentication for root user in Ubuntu linux

Once you had set root password in Ubuntu Linux, you can also check whether SSH is enabled for the root user. First, check whether “PermitRootLogin” property value is set as “yes” in /etc/ssh/sshd_config file using vim editor.

$ sudo vi /etc/ssh/sshd_config

If you use SSH keys for secure login and wanted to allow root user to SSH from different/ third party tools like Putty or WinSCP, then set the following properties values as “yes”.

PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes

Disable root user account in Ubuntu Linux

To disable the root user account in Ubuntu linux, you need to execute the following command.

$ sudo passwd -dl root
passwd: password expiry information changed.

After disabling root user account, if you try to become super user, you will get “Authentication Failure” response as shown below.

$ su
Password:
su: Authentication failure

That’s it. You had learnt how to set or change root password in ubuntu linux, then how to enable SSH password authentication for root user and also how to disable root user account.

Hope it helped 🙂

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments