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 🙂
- Docker: Error response from daemon: OCI runtime create failed: container_linux.go:349
- How to find which users belongs to a specific group in linux
- Give write permissions for specific user or group for specific folder in linux
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- GCP Virtual Private Cloud (VPC) Networks Fundamentals
- How to create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- Create non-root SSH user account and provide access to specific folders