Centos7 learn how to add users and user groups

  • 2020-06-15 11:00:32
  • OfStack

Centos is used more often than Ubuntu, so there is ambiguity between the useradd and adduser commands. On Ubuntu it is two commands and on Centos it is the same command. adduser is linked


# ll /usr/sbin/ | grep user 
lrwxrwxrwx. 1 root root  7 10 month  30 17:09 adduser -> useradd 
-rwxr-x---. 1 root root 114064 6 month  10 09:16 useradd 

1. Add users, Centos has no interactive actions! After creating the user, you must change the password or you cannot log in


# useradd dev # Create a user  
# passwd dev # Change the password  
 Change user  dev  The password   .  
 The new   Password:  
 Reenter the new   Password:  
passwd : All authentication tokens have been successfully updated.  

2. Add sudo permissions for new users, otherwise it is not appropriate to ask root boss for everything, you know!

1) Add writable permissions to sudoers file


# chmod -v u+w /etc/sudoers 
"/etc/sudoers"  The permission mode of is retained as 0640 (rw-r-----) 

2) Add new user information to the sudoers file ## Allow root to run any commands anywher. The modified result is as follows


## Allow root to run any commands anywher 
root ALL=(ALL) ALL 
dev ALL=(ALL) ALL # Add user information  

3) Cancel sudoers file writable permission


# chmod -v u-w /etc/sudoers 
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----) 

Build team


groupadd test             // new test The working group 

Create new users and add working groups


useradd -g test phpq        // new phpq User and add to test The working group 

Note: : -ES47en group -d home directory - SHELL used by s

Add workgroups to existing users


usermod -G groupname username  Or: gpasswd -a user group

Added: Ways to view users and user groups

User list file: /etc/passwd
User group list file: /etc/group
Check which users are on the system: ES67en-ES68en: -ES69en 1 /etc/passwd
View the users who can login to the system: cat /etc/passwd | grep-v /sbin/nologin | cut-d: -f 1
View user 1: w user name
View login user: who
View user login history: last


Related articles: