A command to add users and delete users under a Linux server _linux

Source: Internet
Author: User
Tags parent directory
The meanings of each option are as follows:
-C Comment Specifies a section of an annotation description.
The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the main catalog.
The-G user group specifies the user group to which the user belongs.
-G user group, where the user group specifies the additional group to which the user belongs.
-S Shell file specifies the user's login shell.
The-u user number specifies the user's user number, and if the-o option is available, the other user's identification number can be reused.
  User name Specifies the login name of the new account.
For example:
Copy Code code as follows:

# useradd–d/usr/sam-m Sam

This command creates a user Sam where the-D and-m options are used to produce a home directory/usr/sam (/usr as the parent directory for the default user home directory) for the login Sam.
# useradd-s/bin/sh-g group–g adm,root Gem
This command creates a new user gem, whose login shell is/bin/sh, which belongs to the group user groups and also to the ADM and root groups, where the group groups are the primary groups.
Adding a user account is to add a record to the new user in the/etc/passwd file, while updating other system files such as/etc/shadow,/etc/group, etc. The contents of these files will be described in detail later.
Linux provides an integrated system management tool, userconf, which can be used to manage user accounts uniformly.
If a user's account is no longer in use, it can be removed from the system. Deleting a user account is to remove the user record from the system files such as/etc/passwd and, if necessary, delete the user's home directory. Delete an existing user account using the Userdel command, in the following format:
   userdel Option User name
The commonly used option is-r, which is to delete the user's home directory together.
For example:
# Userdel Sam
This command deletes the user Sam's record in the system file (mainly/etc/passwd,/etc/shadow,/etc/group, and so on) while deleting the user's home directory.
Modify the user account is based on the actual situation to change the user's related properties, such as user number, home directory, user group, login shell and so on.
Modify the information of an existing user using the Usermod command, in the following format:
Usermod option User Name
Common options include-C,-D,-M, G, G, S,-u, and-O, and the meanings of these options are the same as those in the Useradd command, which can specify a new resource value for the user. In addition, some systems can use the following options:
-L New User name
This option specifies a new account that will change the original username to the new username.
For example:
# usermod-s/bin/ksh-d/home/z–g developer Sam
This command modifies the login shell of the user Sam to Ksh, the home directory to/home/z, and the user group to developer.
One important aspect of user management is the management of user passwords. The user account was created without a password, but is locked by the system and cannot be used, and must be assigned a password before it can be used, even if a null password is specified.
The shell command that specifies and modifies a user's password is passwd. A superuser can specify a password for himself and other users, and a normal user can only use it to modify his or her password. The format of the command is:
passwd option User Name
Options you can use:
-L locks the password, that is, the account is disabled.
-u password unlock.
-D makes the account password-free.
-F forces the user to modify the password at the next logon.
If the default user name, the password for the current user is modified.
For example, if the current user is a SAM, the following command modifies the user's own password:
$ passwd
Old password:******
New password:*******
Re-enter New password:*******
If you are a superuser, you can specify any user's password in the following form:
# passwd Sam
New password:*******
Re-enter New password:*******
Ordinary users modify their own password, the passwd command will ask the original password, verify that the user input two times after the new password, if the password entered two times, the password will be assigned to the user, and the root user to specify the password, you do not need to know the original password.
For the sake of system security, users should choose a more complex password, for example, preferably with a 8-bit long password, which contains uppercase, lowercase letters, and numbers, and should be different from names, birthdays, and so on.
When you specify a blank password for the user, the following form of command is performed:
# passwd-d Sam
This command deletes the password for the user Sam so that the system will no longer ask for the password the next time the user Sam logs on.
The passwd command can also lock a user with the-l (lock) option so that it cannot log on, for example:
# passwd-l Sam
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.