Linux User Management

Source: Internet
Author: User

we are logged in Linux When you finish entering your account and password, Linux will first find /etc/passwd If there is an account in the file, if not, then jump out, if any, he will read the account User ID and the Group ID at the same time the root directory of the account and Shell also read it out. Then check the password list, Find the account number and UserID we just entered in/etc/shadow , and Check if we have entered the correct password. Everything is right we can log in to the current user shell.

1. Add a new user account: Useradd

The syntax is as follows:
Useradd option User Name
Each of these options has the following meanings:
-C Comment Specifies an annotative description.
The-D directory specifies the home directory, and if this directory does not exist, it can be created by using the-M option.
The-G user group specifies the user group to which the user belongs.
-G user Group, user group specifies the additional group to which the user belongs.
-S Shell file specifies the user's login shell.
-u user number specifies the user's user number, and if you have the-o option, you can reuse the other user's identification number.
-P This command is required to provide MD5 code encryption password, the ordinary number is not.

Useradd-g root-d/home/rusky-m testuser The command adds a user Testsuer, specifies that the owning group is root, and that the TestUser directory is/home/rusky

2, User password management passwd

User account has just been created without a password, is locked by the system, can not be used, it must be given a password before it can be used, even if it is a blank password.
The shell command that specifies and modifies the user's password is passwd. The ultimate user can specify passwords for themselves and other users, and ordinary users can only modify their own passwords. The format of the command is:
Code:
passwd option User Name
Options available for use:
-L locks the password, which disables the account.
-u password to unlock.
-D make the account no password.
-F forces the user to modify the password the next time they log on.
If the default user name, the password for the current user is modified.
For example: Assuming the current user is Sam, the following command modifies the user's own password:
$ passwd
Old password:******
New password:*******
Re-enter New password:*******
If you are the ultimate user, you can specify the password for any user in the following form:
# passwd Sam
New password:*******
Re-enter New password:*******
Ordinary users to modify their own password, the passwd command will first ask the original password, verify and then require the user to enter two times the new password, if the password two times the same, then the password is assigned to the user, and the ultimate user to specify a password for the user, you do not have to know the original password. For security reasons, the user should choose a more complex password, the best use of not less than 8-bit password, the password contains uppercase, lowercase letters and numbers, and should be different from name, birthday and so on.

When you specify an empty password for a user , the following forms of command are executed:
Code:
# passwd-d Sam
This command removes the password for the user Sam so that the next time the user Sam logs on, the system will no longer ask for the password.
The passwd command can also lock a user with the-l (lock) option so that it cannot log on, for example:
Code:
# passwd-l Sam

3. Modify user account-usermod

Syntax: Usermod [-lu][-c < remarks >][-d < login directory >][-e < expiration >][-f < buffer days >][-g < group >][-g < group >][-l < account name >][-s][-u [user account]

Parameters:
-C Modify the note text for the user account.
-D modifies the directory at which the user is logged on.
-e Modify the expiration date of the account.
-F changes the number of days after the password expires to close the account.
-G modifies the group to which the user belongs.
-G modifies the additional group to which the user belongs.
-L Modify the user account name.
-L LOCKS the user password to invalidate the password.
-S modifies the shell used by the user when they log in.
-U modifies the user ID.
-U unlocks the password.

Example: usermod-d/home/rusky2-m test-user change user test-user home directory to/home/rusky2

4. User Delete Usedel

If a user account is no longer in use, it can be removed from the system. Deleting a user account is to delete the user record in the system files such as/etc/passwd, and delete the user's home directory if necessary. Delete an existing user account using the Userdel command.
Userdel [-R,-f] Username

-F means that the user is forcibly deleted, even if the user is already logged on to the Linux system. The most common option for
is-R, which is to delete the user's home directory.
For example:
# userdel-r Sam
This command removes the user Sam in the system file (mainly/etc/passwd,/etc/shadow, /etc/group, etc.), while deleting the user's home directory.

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.