I currently manage a CentOS 7 server and need to add and delete users. I am familiar with the basic commands for adding users, but I am not sure how to add sudo privileges to the user or delete the user and all files in the user’s home directory.
Adding or removing users in the centos server is very simple. I will try to explain how to add, manage, and delete users. Let’s use the username “jonny” as an example user. However, you can use any username of your choice.
Adding Users
To add a new user, use the command “sudo adduser [username]” in the terminal.
sudo adduser jonny
This will create a new user with the specified username.
Setting a Password
To set a password for the new user, use the command “sudo passwd [username]”.
sudo passwd jonny
You will be prompted to type in the password twice to confirm it.
Granting Sudo Privileges
To give the new user the ability to execute commands with root (administrative) privileges, you will need to give them sudo access. You can add the user to the wheel group (which gives sudo access to all its members by default). Use the command “sudo usermod -aG wheel [username]”.
sudo usermod -aG wheel jonny
Checking Sudo Privileges
To check which users have sudo access, you can use the lid command. This will show you the usernames and UIDs associated with the group.
sudo lid -g wheel
The output should look like this.
jonny(uid=1001)
Deleting Users
To delete a user, use the command “sudo userdel [username]”.
sudo userdel jonny
If you want to delete the user’s home directory and the user account, use the command “sudo userdel -r [username]”.
sudo userdel -r jonny
By following these steps, you can effectively manage users on your CentOS 7 server, giving them only the access they need to perform their tasks.