How to change root password on CentOS Linux

I am a new user of CentOS Linux servers. I need to change the password for root user account on CentOS Linux. How do I change the root password on CentOS Linux using command line options?

Introduction – You need to use the passwd command. It is used to update the user’s authentication token(s) i.e. password. Let us see how to change the root user password on CentOS Linux version 5/6/7 and 8 using the command line.

How to change root password on CentOS Linux

The procedure for changing the password of root is as follows:

  1. First, log in to the CentOS Linux server using ssh or console
  2. Open a shell prompt and type the passwd command to change root password in CentOS Linux
  3. The actual command to change the password for root on CentOS Linux is sudo passwd root

NOTE: Please note that {vivek@centos7:~ }$ is my shell prompt. You need to type commands after the $ prompt.

CentOS Linux change root password command

I am going to log in to my CentOS Linux 6.x/7.x/8.x server using the ssh command:
{vivek@centos7:~ }$ ssh vivek@centos7-server
Once logged in enter the command passwd as follows:
{vivek@centos7:~ }$ sudo passwd root
First you need to type the password for vivek user. After that the passwd command asks for the new password, which you will have to enter two times:

Changing root account passwords on an CentOS Linux based system

The next time you log in to a CentOS Linux server/workstation, use the new password.

Slightly different procedure for changing passwords in CentOS Linux

One can use the following procedure too:
{vivek@centos7:~ }$ ssh user@your-centos-server-name-ip
Become a root user via the su command or sudo command:
{vivek@centos7:~ }$ sudo -i
{vivek@centos7:~ }$ su -
Finally change your root user password:
# passwd

How to delete user’s password

We can delete a user’s password and make it empty. This is a quick way to disable a password for an account. For example, set the user named ‘vivek’ account passwordless:
$ sudo passwd -d {user-name}
$ sudo passwd -d vivek

Please do not make root user’s password empty for security reasons.

Force user to change their password at the next login

We can immediately expire an account’s password. This in effect can force a user to change their password at the user’s next login as per their needs:
$ sudo passwd -e {user-name}
$ sudo passwd -e wendy

Getting help

Type the following command:
$ passwd --help
$ man passwd


To change your own password on a CentOS, run:
$ passwd
Set up a new password for root:
$ sudo passwd root
And to change password for any other users:
$ sudo passwd userName
$ sudo passwd tom

This page explained the process for changing the password of root user using the passwd command on a CentOS Linux. See CentOS Linux documents page here for more info or read other tutorials:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Rudra Dec 13, 2016 @ 19:56

    Open KVM console or ssh into the box:
    ssh rudra@linode-server-ip
    su -

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum