Linux new user and rights assignment

Source: Internet
Author: User

1. Create a new User: TestUser

command :#useradd Option user name

Options :

-C Comment Specifies an annotative description.

The-D directory specifies the home directory, and if this directory does not exist, the-m option can be used to create the master directory.

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.

Example :

[Email protected]/]# useradd testuser

2. Delete TestUser users

command :#userdel Option user name

Options :

-R Its role is to remove the user's home directory together.

Example :

[Email protected]/]# Userdel testuser

[email protected]/]# Cd/home

[Email protected]/]# RM-RF testuser

3. Modify the user

command :#usermod Option user name

Options :

-C,--comment comment new value of the GECOS field

-D,--home home_dir new home directory for the user account

-E,--expiredate expire_date set account expiration DATE to Expire_date

-F,--inactive inactive set password inactive after expiration to inactive

-G,--gid Group Force use Group as new primary group

-G,--groups groups new list of supplementary groups

-A,--append append the user to the supplemental GROUPS mentioned by the-g option without removing hi M/her from other groups

-H,--help display this help message and exit

-L,--login new_login NEW value of the login name

-L,--lock lock the user account

-M,--move-home move contents of the home directory to the new location (with only with-d)

-O,--non-unique allow using duplicate (Non-unique) UID

-p,--password password use encrypted password for the new password

-S,--shell shell new login shell for the user account

-U,--uid uid new UID for the user account

-U,--unlock unlock the user account

-Z,--selinux-user new SELinux user mapping for the user account

Example :

Change the user group to developer.

# Usermod–g Developer Sam

4. User password (password) management:

An important part of user management is the management of user passwords. The user account has just been created without a password, but is locked by the system, cannot be used, it must be given a password before it can be used, even if a blank password is specified.

command :#passwd Option user name

Options :

-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.

Example :

[Email protected]/]# passwd Sam

New password:*******

Re-enter New password:*******

5. Add a group:

command :#groupadd Option User Group

Options :

-G GID Specifies the group identification number (GID) of the new user group.

-O is commonly used with the-G option, which means that the GID of the new user group can be the same as the GID of the user group already in the system.

Example :

[Email protected]/]# Groupadd group1

6. Delete a group:

command :#groupdel user Group

Options :

Example :

 [Email protected]/]# Groupdel group1

7. Delete a group:

command :#groupmod Option User Group

Options :

-G GID Specifies a new group identification number for the user group.

The-O is used in conjunction with the-G option, and the user group's new GID can be the same as the GID of the user group already in the system.

-N New user Group change user group name to new name

Example :

This command changes the identification number of the group group2 to 10000 and the group name to Group3.

[Email protected]/]# groupmod–g 10000-n group3 group2

8. The independence of the new user

Modify directory permissions so that Linux can only view its own root directory per account and cannot view directories for other accounts. First, go to the folder where all the users are in the Linux system.

[email protected]/]# Cd/home/testuser

This is to say that the settings testuser This directory only Lili can be viewed, Other accounts under Linux cannot be viewed.

[Email protected]/]# chmod GO-RW testuser

9. Other commands:

[[email protected]/]# cat/etc/passwd can view the user's pass

[[email protected]/]# Cat/etc/shadow can view user name

[[email protected]/]# Cat/etc/group can view group

Linux new user and rights assignment

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.