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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
