How to Add a Root User on Linux

When you first start using a fresh Linux server, adding and removing users is one of the most basic tasks that you should know how to do. When you create a new server, you are only given the root account by default. While this gives you a lot of power and flexibility, it is also dangerous to regularly use an account with so much power; for example, a root user is more vulnerable to security exploits, since any commands run under that account can affect the server's entire filesystem.

Add a Root User and Set a Password

To add a new user, use the adduser command, replacing the "newuser" with your preferred username

sudo adduser newuser

Providing the user with a new password, typing and confirming the new password when prompted

sudo passwd newuser

Grant a User Root Privileges

Opening the sudoers file with this command

sudo /usr/sbin/visudo

Adding the user's name and the same permissions as root under the the user privilege specification will grant them the sudo privileges

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
newuser ALL=(ALL)       ALL

Delete a root User

You can delete them with a single command

sudo userdel newuser

You can add the flag "-r" to the command if you would like to simultaneously remove the users's home directory and files

sudo userdel -r newuser

Comments

Popular posts from this blog

Reduce TIME_WAIT Socket Connections