Ubuntu users and permissions (3)

  
        

Seven, add and delete group related commands

The same we must first introduce two important configuration files: /etc/group and /etc/gshadow, the previous one is actually the same as /etc/passwd The latter is the password table for the group. First look at the long sample:

root:x:0:

adm:x:4:m,syslog

m:x:1000:

This is part of the intercepted /etc/group. Each line is divided into four segments by a colon. The first segment is the group name; the second segment is the password; the third segment is the gid; the fourth segment is the member below the group. It is.

We see that the fourth segment of the root and m groups is empty, and the fourth segment of the adm group has two members. Why is there such a difference? The group that each user joins is divided into a primary group and a secondary group. The primary group refers to the group that is bound when the user account is just created. Just look at the fourth paragraph in /etc/passwd. You can know which main group of the user is. See the information of user m: m:x:1000:1000:m,,,:/home/m:/bin/bash Obviously the main group of user m is m. Then the name of each account will not appear in the fourth paragraph of the main group in /etc/group, because to some extent this is self-evident or default; if a user appears in the fourth paragraph That means that the group is not its main group.

There is also a concept called a valid group, although a user can join multiple groups and have the appropriate permissions, but this is for existing files or directories. If a user wants to create a new file or directory, which group of the user does it belong to? The answer is a valid group, which is the group the user is in at the moment. We know that at a certain time, a user can only be active in one group, even if he has permissions to other groups. For example, a leader who manages three departments has the right to have three groups, but at each moment he can only sit in the office of a particular department, but can't sit in three offices at the same time, even if he has two others. The right to enter the office.

Use the groups command to view all the groups to which the current user belongs. The first one is the effective group for the user. Use the newgrp command to switch between active groups, similar to the leader going to another office. Then it is the default, that is, when a user logs in to Linux, which is the effective group? What is the office that goes to the first place every day? The answer is the main group above, where it is called the initial group, but no matter which name, it is the fourth group of /etc/passwd.

root:*:: daemon:*::

m:!::

This is part of the intercepted /etc/gshadow, each line is also separated by a colon The four segments are the group name, password, group administrator, and member. If the password segment is! Or *, it means that the reorganization cannot log in, that is, it cannot be switched by newgrp.

Add group command

groupadd -g/r groupname -g followed by gid, plus -r means that the system group is created, ie the second column of /etc/gshadow will Become an asterisk or an exclamation mark.

Modify group command: groupmod is similar to usermod, ie ——groupmod [-g gid] [-n group_name]

Delete group command: groupdel groupname , but this command is somewhat The place to pay attention, because it will fail in some cases, because the initial group of the user is the group, so you must first remove the binding, that is, modify the gid of the user in /etc/passwd or delete it directly. The user.

VIII, other commands

1) In addition to the above groups can view the group information, there is an id command, you can view more information, just enter the id directly in the terminal, No need to add parameters.

2) passwd command passwd [-lunxwS] username

-l : lock the password of the username account, modify the password bar in /etc/shadow~ -u : Unlock the lock of -l! -n : followed by the number of days (number), the shortest number of days; that is, the fourth column in /etc/shadow; -x: followed by the number of days (number), the longest number of days; That is, the fifth column in /etc/shadow; -w: followed by the number of days (number), warning days; that is, the sixth column in /etc/shadow; -S: displays the current information about this username.

Copyright © Windows knowledge All Rights Reserved