How to Verify if the Root User Has a Password on Linux Systems

ubuntu root user password

Check if the Root User Account is Secured with a Password in Ubuntu

ubuntu

Method 1: Check /etc/shadow

  1. Open your terminal.
  2. Use sudo to view the contents of the /etc/shadow file:
    sudo cat /etc/shadow | grep root
  3. The output will look something like this:
    root:$6$abcd1234$abcdefghijklmnopqrstuvwx:18578:0:99999:7:::

Interpret the output:

If the second field (after root : contains a hash, it means the root user has a password set. Suppose the second field is empty or contains a special character like ! or \*, it means the root user does not have a password set.

Method 2: Use passwd Command

Another way to check if the root user has a password is to use the passwd command:

  1. Open your terminal.
  2. Use sudo to check the status of the root password:
    sudo passwd -S root
  3. The output will indicate the password status:
    1. root P xxxxxx (where P stands for Password): The root user has a password set.
    2. root L xxxxxx (where L stands for Locked): The root user does not have a password set.
    3. root NP xxxxxx (where NP stands for No Password): The root user does not have a password set.