Linux_ User/user group

Source: Internet
Author: User

One, the user added

1. Account Add

[Email protected] tmp]# Useradd ERRSR

The user entry is appended to the/etc/passwd file and the folder that belongs to the user is automatically generated under the/home folder, which is the user name for the default user group

2. Password settings

[[email protected] ~]$ passwd errsrpasswd:only root can specify a user name.  #提示修改密码只能由root用户来完成 [[email protected] ~]$ Su-rootpassword: [[email protected] ~]# passwd errsrchanging password for user Errsr.new password:retype New Password:passwd:all authentication tokens updated successfully.

3. Add a user group

[Email protected] ~]# Groupadd Learn

4. Existing users, change their user group to learn


5. Set up user groups at the same time when creating a new user

[[email protected] ~]# useradd-g learn ERRSR #-g (group) on behalf of the user group-D (directory) represents home directory-S (shell) The shell used after creating a new user

Second, user close and delete

1. Close user account (suspend use, note that root can switch directly to the user to continue operation)

[Email protected] ~]# passwd peter-l #锁定账号Locking password for user peter.passwd:Success    [[email protected] ~]# su -Errsr[[email protected] ~]$ su-peterpassword:su:incorrect password[[email protected] ~]$ su-password:[[email Protec Ted] ~]# passwd peter-uunlocking password for user peter.passwd:Success

Another way (to modify a file): Precede the second field (password) of the row that belongs to the user in the/etc/shadow file with a * on it. To restore the user, remove *

2. Delete a user

[[email protected] ~]# userdel-r ERRSR #-r with ERRSR user group, home directory ERRSR (including sub-files, subfolders) are deleted together

Of course separate write as follows

[Email protected] ~]# Userdel Peter [[email protected] ~]# Groupdel Peter [[email protected] ~]# usermod–g Peter Peter # -G means to forcibly delete Peter (including files, subfolders) under Home directory

PS: Sometimes this problem is encountered

Userdel:user Liuwenlong is currently logged in

Workaround:

A. Using Lsof | grep ERRSR view ERRSR Process ID

B. kill-9 Process ID

3. If you just want to remove the user from the user group: Edit/etc/group to find the user's line, delete it, in addition

[Email protected] ~]# gpasswd-d Petter Group_name

Third, view user details

[[email protected] ~]# ID rootuid=0 (root) gid=0 (root) groups=0 (root)

Or

[Email protected] ~]# CAT/ETC/PASSWD | grep ^rootroot:x:0:0:root:/root:/bin/bash

Iv. Related concepts and knowledge

A. The correspondence between users and user groups is: one-to-many, one or one-to-many or many-to-many

     Single-to-one: a user can be the only member of a group

Many-to-one: multiple users can be members of a unique group and do not belong to other user groups, such as Beinan and Linuxsir two users only belong to the Beinan user group

One-to-many: a user can be a member of more than one user group, such as Beinan can be a member of the root group or a member of the Linuxsir user group, or it can be a member of the ADM user group

Many-to-many: multiple users correspond to multiple user groups, and several users can belong to the same group, in fact, many-to-many relationships are the extension of the previous three, and understanding the above three, this one can understand

B. User-related configuration files

      /ETC/PASSWD Note: User profile

/etc/shadow Note: User Shadow password file

C. Configuration files related to user groups (group)

      /etc/group Note: User groups (group) profiles

/etc/gshadow Note: Shadow files for user groups (group)

D. managing Users (user) tools or commands

      Useradd Note: Add Users

AddUser Note: Add Users

passwd Note: Set a password for the user

Usermod Note: Modify the user command, you can use Usermod to modify the login name, the user's home directory, etc.

Pwcov Note: Synchronizing users from/etc/passwd to/etc/shadow

PWCK Note: PWCK is verifying that the user profile/etc/passwd and/etc/shadow file contents are legitimate or complete

Pwunconv Note: Pwcov is the reverse operation, is created from/etc/shadow and/etc/passwd/etc/passwd, and then delete the/etc/shadow file

Finger Note: View the user Information tool

ID Note: View the user's UID, GID, and user group to which they belong

CHFN Note: Change user Information tool

SU Note: User Switching tool

sudo note: sudo is executed by another user (execute a command as another user), SU is used to switch the user, and then the user is switched to complete the corresponding task,

However, Sudo can execute commands directly behind it, such as sudo does not require root password to perform root assignment and only root can execute the corresponding command;

But you have to edit/etc/sudoers through Visudo to achieve

Visudo Note: Visodo is the command to edit the/etc/sudoers, or you can edit the/etc/sudoers directly with VI without this command.

Sudoedit Note: Same as sudo function

E. Tools or commands to manage user groups (group)

      Groupadd Note: Add a user group

Groupdel Note: Delete a user group

Groupmod Note: Modify user group information

Groups Note: Displays the user group to which the user belongs

Grpck

GRPCONV Note: Synchronize or create/etc/gshadow with the file contents of/etc/group and/etc/gshadow, and create if/etc/gshadow does not exist

Grpunconv Note: Synchronize or create/etc/group with/etc/group and/etc/gshadow file contents, then delete the Gshadow file

Linux_ User/user group

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.