Operations 4 min read

Enable or Disable Ubuntu’s Root Account in Minutes

Learn step‑by‑step how to activate the root user on Ubuntu, assign a password, configure sudo for password‑less access, and later lock or disable the root account by expiring its password, with clear command examples and safety tips.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Enable or Disable Ubuntu’s Root Account in Minutes

Ubuntu disables the root account by default for security. This guide shows how to enable and later disable the root user.

Sudo Permissions and Adding Users to the sudo Group

To grant sudo rights, add the user to the sudo group: sudo usermod -aG sudo username After this, prepend sudo to commands to run them with elevated privileges.

Configuring Password‑less sudo

Edit the sudoers file with visudo and add NOPASSWD: to the desired rule, e.g.: %sudo ALL=(ALL:ALL) NOPASSWD: ALL This allows members of the sudo group to execute commands without entering a password.

Enabling the Root Account

Set a password for the root user (requires sudo rights): sudo passwd root Enter and confirm the new password. Afterwards you can switch to the root shell with su - and the password you set.

Disabling the Root Account

To lock the root account, expire its password: sudo passwd -l root After expiring the password, attempts to log in as root using su will fail with an authentication error.

Security Reminder

When setting passwords, use a strong, unique password of at least 16 characters, containing uppercase, lowercase, digits, and special symbols.

Illustration of enabling root user on Ubuntu Linux
Illustration of enabling root user on Ubuntu Linux
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

linuxSystem AdministrationUbuntupasswordSudo$root
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.