Users and user groups of linux study notes

To add user adduser in centos7 to create a user group, we use the groupadd command. In fact, the complicated point is the command of the user's group and group permissions. Let's briefly learn the creation and deletion of users and user groups, etc.

Subdivided user accounts (normal user accounts, super user accounts) In addition to user accounts, there are group accounts. The so-called group account is a collection of user accounts. There are two types of centos groups, private groups and standard groups. When creating a new user , if the group to which he belongs is not specified, centos will create a private group that is the same as the user, and this private group only includes the user himself. Standard groups can accommodate multiple users. If you want to use standard groups, you should specify the group to which he belongs when creating a new user. On the other hand, the same user can belong to multiple groups, such as the leader of a unit. Group and technical group, lik is the technical director of the unit, so he belongs to the leadership group and technical group. When a user belongs to multiple groups, the group to which the user belongs after logging in is the main group, and other groups are additional groups. 2. The account system files in the Linux environment are mainly in four files: /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow. I won't say much about the basic meaning. Let me focus on it. The uid of root is 0, and the standard account from 1 to 499 is the system's standard account. Ordinary users start from uid 500.

1. Create a user:

[root@localhost home]# adduser test02
[root@localhost home]# passwd test02
Change the password of user test02.
New password:
Re-enter new password:
passwd: All authentication tokens have been successfully updated.
[root@localhost home]#

 

2. Set up a working group

[root@localhost home]# groupadd test02
groupadd: "test02" group already exists (usually when creating a user, use the username as the default group)
[root@localhost home]# groupadd test03 (the above prompt will not appear)

 

3. Create new users and add workgroups


[root@localhost home]# useradd -g test03 guset
[root@localhost home]# id guset
uid=1004(guset) gid=1004(test03) 组=1004(test03)
[root@localhost home]#

Note: -g belongs to the group -d home directory -s SHELL used

 

4. Add workgroups to existing users

 

[root@localhost home]# usermod -a -G test03 test02 (add user test02 to test03 group)
[root@localhost home]# id test02
uid=1003(test02) gid=1003(test02) group=1003(test02) ,1004(test03)
[root@localhost home]#

 

5. Temporary shutdown: Just add * in front of the second field (password) of the line belonging to the user in the /etc/shadow file. To restore the user, remove the *. Or use the following command to close the user account:

Close the user account
[root@localhost home]# passwd imix -l
lock the password of user imix.
passwd: The operation is successful
[root@localhost home] #The
user cannot log in after being locked.
Login as: imix
Access denied
[email protected]'s password:

User unlock:


[root@localhost ~]# passwd imix -u
unlocks the password of user imix.
passwd: successful operation
[root@localhost ~]#

 

6. Permanently delete the user account

[root@localhost ~]# userdel test02
[root@localhost ~]# groupdel test02
groupdel: "test02" group does not exist
[root@localhost ~]# usermod -G test02 test02 (forcibly delete the user's home directory and home directory all files and subdirectories)
usermod: "test02" group does not exist
[root@localhost ~]#

7. Delete the user from the group, edit /etc/group to find the GROUP1 line, delete A or use the command gpasswd -d A GROUPNAME

[root@localhost etc]# gpasswd -d test test
is removing user "test" from group "test"
gpasswd: user "test" is not a member of "test"
[root@localhost etc]#

 

8. Display user information


[root@localhost etc]# id test
uid=1002(test) gid=1002(test) 组=1002(test),1001(www)
[root@localhost etc]# cat -n /etc/passwd
     1  root:x:0:0:root:/root:/bin/bash
     2  bin:x:1:1:bin:/bin:/sbin/nologin
     3  daemon:x:2:2:daemon:/sbin:/sbin/nologin
     4  adm:x:3:4:adm:/var/adm:/sbin/nologin

Added: Ways to view users and user groups

User list file: /etc/passwd
User group list file: /etc/group

Check which users are in the system: cut -d : -f 1 /etc/passwd
Check the users who can log in to the system: cat /etc/passwd | grep - v /sbin/nologin | cut -d : -f 1
View a user: w Username
View logged in users: who
View user login history: last

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326889403&siteId=291194637