How to set a root password on Ubuntu 22.04 Jammy Jellyfish Linux

Although it is conventional to log into the root account on some Linux systems, by default Ubuntu 22.04 does not allow us to log into root and instead expects us to achieve root permissions through use of sudo. However, it is still possible to set a root password and subsequently log directly into root. In this tutorial, you will see how to set a password for the root account on Ubuntu 22.04 Jammy Jellyfish.

In this tutorial you will learn:

  • How to set root password
  • How to log into root account
How to set a root password on Ubuntu 22.04 Jammy Jellyfish Linux
How to set a root password on Ubuntu 22.04 Jammy Jellyfish Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 22.04 Jammy Jellyfish
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to set a root password on step by step instructions



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!

WARNING
Ubuntu 22.04 installation comes with a blank root password as default. This is a security precaution since the user is never expected to login as the root user. For any privileged administration tasks the user is recommended to use the sudo command.

Setting a root password comes with risks, hence if possible you should try to avoid it. If you only need to gain a temporary command line root access this can be achieved with the sudo -i command.

  1. To set a root password open up a terminal window and execute the following sudo command. First, you need to enter your user password ( given that you are part of the sudo administration group ) after which enter and retype a new root password:
    $ sudo passwd
    [sudo] password for linuxconfig: 
    New password: 
    Retype new password: 
    passwd: password updated successfully
    
  2. All done, you should now be ready to login with a new root password. Try it now:
    $ su
    password:
    
  3. Use the whoami command to confirm that you are logged in as a root user:
    # whoami
    root
    

Closing Thoughts




In this tutorial, you saw how to set a root password on Ubuntu 22.04 Jammy Jellyfish Linux. This allows you to log directly into the root account, rather than only being able to access root permissions with the sudo command. Although it is a security recommendation to never use the root account, some administrators may be very accustomed to using it on other Linux distros and want the functionality on Ubuntu 22.04 as well.