User, user group and permission management of Linux study notes

View all users and all user groups under linux:
groups View the group members of the currently logged in user
groups gliethttp View the group of the gliethttp user and
whoami members of the group View the current login user name
/etc/group file contains all groups
/etc/shadow and all usernames that exist in the /etc/passwd system

User group management:
1. groupadd user group name
eg, gruopadd grp1#Create user group grp1
2. gruopdel user group name

User management:
1. useradd [options] user name
eg, useradd usr1#Create user usr1;
useradd -u 322 -g grp1 -G grp2 usr1 #Create user usr1, UID is 322, main user group is grp1, additional user group is grp2;
2. passwd username#create the user's login password;
3. userdel username#delete the user;
4. usermod [options] username#modify user attributes
eg, usermod -g grp2 usr1# set the main user group of user usr1 Change to grp2;'
5. chown [user]:[user group] file list #Change the user and group to which the file belongs
eg, chown usr1 myfile#Set the user of the file myfile to usr1
chown :gep1 myfile#Set the user group to which the file myfile belongs For grp1
chown usr1:grp1 myfile#Set the user and user group to which the file myfile belongs to usr1 and grp1
6, chmod
eg, chmod a=–x demon#All users have execution permission to the demon
chmod u+r–demon#The owner User (own user) has read permission to demon
chmod g=-w- demon# The owner user group (all other users in the group) has write permission to demon
chmod o=rwx demon# All other users have read, write and execute permission to demon
chmod 666 demon# The owner user (self) can read and write to the demon, other users in the group can read and write to the demon, and other users have read and write permissions to the demon

"+" adds permission;
"-" deletes permission;
"=" assigns permission;

Related tools or commands for managing users (users) and user groups (groups);

1) Tools or commands for managing users;

useradd Note: add user

adduser Note: add user

passwd Note: Set a password for the user

usermod Note: To modify user commands, you can use usermod to modify the login name, the user's home directory, etc.;

pwcov Note: Synchronize users from /etc/passwd to /etc/shadow

pwck Note: pwck is to verify whether the content of the user configuration files /etc/passwd and /etc/shadow files is legal or complete;

pwunconv Note: It is the reverse operation of pwcov. It creates /etc/passwd from /etc/shadow and /etc/passwd, and then deletes the /etc/shadow file;

finger Note: View the user information tool id Note: View the user's UID, GID and the user group chfn to which they belong Note: Change the user information tool

su Note: user switching tool sudo Note: sudo is to execute a command as another user, su is used to switch users, and then complete the corresponding tasks by switching to the user, but sudo can be used later Execute commands directly, for example, sudo can execute root assignments without a root password. Only root can execute the corresponding commands; but you have to edit /etc/sudoers through visudo.

visudo Note: visodo is a command to edit /etc/sudoers; you can also use vi to edit /etc/sudoers without this command, and the effect is the same;

sudoedit Note: Similar to sudo function;

2) Tools or commands for managing user groups;

groupadd Note: add user group;

groupdel Note: delete 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 through the contents of /etc/group and /etc/gshadow files, or create if /etc/gshadow does not exist;

grpunconv Note: Synchronize or create /etc/group through the contents of /etc/group and /etc/gshadow files, then delete the gshadow file;

Manage permissions of users and user groups:
Modification 1: Change permissions in absolute mode
Think of each digit as a sum:
execute permission= 1
write permission= 2
write and execute (1+2)= 3
read permission= 4
read and execute (4+1)= 5
read and write (4+2)= 6
read, write and execute (4+2+1)= 7

That is, you can use the chmod command to set permissions on a directory:
chmod can use 3 numbers to express users, user groups, and other users:
such as chmod 777 /test
(the first 7 of the
number , and the second 7 of the number It represents the permissions of the user group, the third 7 of the
number represents the permissions of other users)

Modification 2: Change permissions in symbolic mode (add permissions for adding definitions on the original basis)
You can also change file permissions with letters:
u = user (yourself)
g = group
a = everyone
r = read
w = write
x = execute
eg:
chmod u+rw file Give yourself read and write permission
chmod u+x filespec Give yourself execute permission.

Change the owner and user group of a linux file:
use the command chown
basic format
chown user:[group] file
where user is the user name, group is the user group name, file is a file or folder, and the content in [] is optional.
Simple example and description:
chown user1:group1 file1
changes the owner of file1 in the current folder to user1, and the owner user group to group1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325699348&siteId=291194637