How to Create and Delete Users on CentOS 7
1. Creating New User logged in as root account
Log in to your server as the root user, as the root user having the privileges to create a new user account.
adduser username
example: create username "yogi"
adduser yogi
Now update the new user's password with "passwd" command.
passwd username
example: update password of user account "yogi"
passwd yogi
2. Deleting User Account logged in as root account
To delete the user account without deleting any of their files, use the below command.
userdel username
example: delete user "yogi"
userdel yogi
To delete the user’s home directory along with the user account itself, use the below command.
userdel -r username
example: delete user account "yogi"
userdel -r yogi
I. Creating New User logged in non-root account having sudo privileges
For non-root user who is having sudo privileges, can use the below command for adding a new user account.
sudo adduser username
example: create username "yogi"
sudo adduser yogi
Now update the new user's password with "passwd" command.
sudo passwd username
example: update password of user account "yogi"
sudo passwd yogi
II. Deleting User Account logged in non-root account having sudo privileges
To delete the user account without deleting any of their files, use the below command.
sudo userdel username
example: delete user "yogi"
sudo userdel yogi
To delete the user’s home directory along with the user account itself, use the below command.
sudo userdel -r username
example: delete user account "yogi"
sudo userdel -r yogi