To create a new sudo user in linux, you need to log in with the root user.
What is a sudo user?
Before creating a user we will first discuss some basics about the sudo user in Linux.
The sudo user is nothing but the user who has permission to run the Linux commands which can not be executed with the regular user.
That means sudo user in Linux executes the commands which need the root user privilege. Sudo users can also run the commands on behalf of other regular users.
Login to the server
To create a new user log into the system with the root user.
You can also execute the same commands which can’t be run with regular users, with the sudo user once you create one.
So for creating the user login to your server with putty with the root user.
Create a user in the Linux (Ubuntu)
You can also execute the same commands which can’t be run with regular users, with the sudo user once you create one
So for creating the user login to your server with putty with the root user.
Create a new user
We will create a user named “new_user”
- type the ssh command below.
$ adduser new_user
Replace “new_user” with the username you want to add.
Then provide the password for the new_user
- Then again type the password to confirm the password prompt.
- After the password, it will ask for some information about the “new_user” like Full name, Room no, Work Phone, Home Phone, etc. Give the required information, or to skip with default values just press Enter.
- After providing all the necessary information, it will again ask for confirmation, press Y and Enter to confirm the details for the new_user.
Now your new_user is created.
add this user to the sudoers list.
Run the following command to add a user to the sudoers list:
$ usermod -aG sudo new_user
Don’t forget to replace the new_user with your username.
This command will add a user to the sudoers list.
You can confirm if the user is really added to to the sudoers list or not by the following command
$ -l -U new_user
If you get the output content like:
User new_user may run the following commands on <your_os>:
(ALL : ALL) ALL
Then we can say that the user is successfully added to the sudoers list which means it can run commands which sudo privileges.
Run the sudo commands with the new sudo user
Logout root user from the server and log in with the new_user
Now you can run any sudo commands with this user. You can also use this user to create new sudo users,
Add new user with the sudo user
For executing the commands you just need to add the “sudo” word before any command.
Like:
$ sudo adduser new_user2
This will create a new user in the system with the name “new_user2”
Grant the sudo privilege to the user with sudo user
$ sudo usermod -aG sudo new_user2
Now your second user is also a sudo user.
Remove/ Revoke the sudo permission from the user
If you want to remove the sudo access from the user type the ssh command below
$ sudo gpasswd -d new_user2 sudo
This will remove the sudo access from the user and the user will become a normal/regular user. You can not now run the sudo commands with new_user2.