编程人 cdmana.com

Learn a Linux command every day (9): useradd / userdel

 picture

recommend Learn one every day Linux command (8):ls

Github Address :

https://github.com/mingongge/...

Command profile

useradd/userdel Create a new user / Delete user , Need administrator permission to operate .

When creating users , If you don't configure the password , The user's default password is not available , therefore ,useradd Orders are generally related to passwd Use with commands , In the next section we will introduce this command .

Grammar format

useradd  Options   user name 
userdel  Options   user name 

Classification of users

  • The super user :root, Have the highest administrative authority on the system ,UID The default is 0.
  • Virtual user : It is also called system user or pseudo user , With certain privileges , Related to system or program services , But there are no real users . Generally not used to log in to the system , It is mainly used to maintain the normal operation of an access , Such as ftp,apache etc. .
  • Ordinary users : It's a restricted user , Generally, new users are ordinary users . By default, only /bin、/usr/bin、/usr/local/bin And the commands in your home directory .

Be careful :UID That is, the identity of each user , Although it can be modified /etc/passwd( Command settings UID No repetition ), But try to be unique , Similar to everyone's ID number. .

Option description

useradd Options

-c # Add remarks , Note text is saved in passwd In the remarks column .
-d # Specify the home directory when the user logs in , Replace system defaults /home/< user name >
-D # Change the default value .
-e # Specify the expiration date of the account , The date format is MM/DD/YY, for example 06/30/12. The default means permanent .
-f # Specify how many days after the password expires to close the account . If 0 The account was immediately deactivated ; If -1 Then the account is always available . The default value is -1.
-g # Specify the group to which the user belongs . Value can make the group name GID. The user group must already exist , The default value of period is 100, namely users.
-G # Specify the additional group to which the user belongs .
-m # Automatically create user login directory .
-M # Do not automatically create the user's login directory .
-n # Cancel the creation of a group named by user name .
-r # Set up a system account .
-s # Specify the... Used by the user after login shell. The default value is /bin/bash.
-u # Designated user ID Number . This value must be unique in the system .0~499 By default, it is reserved for the system user account , So the value must be greater than 499.

userdel Options

-f # Force deletion of user accounts 
-r # Delete the user's home directory and any files in it 
-h # Display help information for the command 

Application example

useradd -s mingongge   
# New system user mingongge
useradd mingongge -u 888    
# Set up ID Try to be greater than 500, To avoid conflict ; commonly 0 To 499 The value between is left to bin、mail Such a system account 
useradd -m -d /home/mingongge mingongge   
# Specify the path to create the user's home directory ,/home/mingongge The directory will be created 
useradd -s /sbin/nologin mingongge     
# Create a user who doesn't have a home directory and can't log in 
useradd -m -G test,sudo mingongge      
# Add users to different user groups when creating test,sudo
useradd -u 2020 -m -g root mingongge       
# Add users mingongge Its id by 2020, And add it to the group root in 

Use useradd -D You can view the default information when creating a new user , Or directly cat /etc/default/useradd

useradd -D
GROUP=888
HOME=/home
INACTIVE=888
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

Modify the default information when creating a new user .

useradd -D -f 999
# Check whether the modification is successful 
useradd -D | grep INACTIVE
INACTIVE=999

Delete user , But don't delete their home directories and files

[root@mingongge ~]# userdel mingongge

Delete user , And delete his home directory and files

[root@mingongge ~]# userdel -r mingongge

Force deletion of users

[root@mingongge ~]# userdel -f mingongge

In the next section we will introduce passwd This command , It is associated with useradd Commands are used in conjunction with , Used to configure / Change the user's password .

Learn one every day Linux command (7):cd

Learn one every day Linux command (6):shutdown

Learn one every day Linux command (5):grep

Learn one every day Linux command (4):awk
image

Scroll to Top