How to set a root password on Ubuntu 18.04 Bionic Beaver Linux

Objective

The objective is to set a root password on Ubuntu 18.04 Bionic Beaver Linux

Operating System and Software Versions

  • Operating System: – Ubuntu 18.04 Bionic Beaver Linux

Requirements

Privileged access to to the system using sudo command is required.

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

Other Versions of this Tutorial

Ubuntu 20.04 (Focal Fossa)

Instructions

Ubuntu 18.04 Bionic Beaver installation comes with a blank root password as default. This is a security precaution as user is expected to never login as the root user. For any privileged administration tasks the user is required to use the sudo command.

Login as Root

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. Consider the following example:

login as root on Ubuntu 18.04 Bionic Beaver Linux



Set root password

The following sudo command will allow you to set the root password:

$ sudo passwd

Follow the prompt to enter and retype the new root password. Once the root password is set use the su command to gain root shell access. The whole procedure is illustrated below.

set root password on Ubuntu 18.04 Bionic Beaver Linux