<> User management and file permissions

Add user

grammar :

useradd user name

Parameter action
-d Specify user account home directory ( The default is /home/“ Create user name ”)
-M Do not create home directory
-e Specify account expiration date
-g Specify the primary group of the account ( Must already exist )
-G Specify the affiliate group to which the account belongs , Groups are separated by commas ( Must already exist )
-n Do not create a private user group with the same name as the user account
-s Specify the user account to use when logging in shell interpreter
-u Specifies the default for the user account UID case 1: Add a user Milan, By default, the user's home directory is /home/Milan useradd Milan
case 2: Add a user zs, Specifies the name of the user's home directory /home/myZs useradd -d /home/Zs zs
appoint , Change Password

grammar :

passwd user name

Attention : If no user name is specified , Is to change the password for the current user
case 1: to ls Specify password as :123456 passwd ls case 2: to zs Specify password as :123456 echo "123456" | passwd
--stdin zs
Parameter action
-l Lock user , Disable their login
-u Unlock , Allow user login
-S Displays whether the user's password is locked , And the name of the encryption algorithm used for the password
-d Clear account password , Unable to log in to the system , Unless the password is reset
--stidn Allow user password modification through standard input , as ``"echo “123456”
delete user

grammar :

userdel user name

'"-r" Is an optional parameter , If this parameter is used , Delete the home directory corresponding to the account while deleting the account ,"-r" General collocation of parameters "-f" Use together , formation "-rf"

as :userdel -rf zs
case 1: delete user Milan, But keep the home directory :userdel milan; useradd milan case 2: Delete user and user home directory , such as :userdel
-rf zs; useradd -d /home/myZs zs userdel -rf zs
Query user information instruction

grammar :
id user name case 1: id root // Show root User information When the user does not exist , Return no such user : no such user
Switch users
grammar : su - user name // Pay attention to join "-" Is to enter the user's home to work when switching users In operation Linux in , If the current user has insufficient permissions , Can pass su
- instructions , High authority user , Switch to user with permission , No password required
View current user , log on user
grammar : whoami/who am i
Note that : Displays the information of the user who logged in to the system for the first time , If used haikang Log in to the system , Yes display haikang information , When from haikang User switches to root User time , Display also haikang Information
be careful who And whoami(who am i) Differences between : whoami( or who am i) Is to display the users currently using the system who Is the user who initially logged in
New group
grammar : groupadd Group name
delete group
grammar : groupdel Group name Case demonstration 1. Add groups directly when adding users appoint : useradd -g User group user name
3. Add a user haikang, Put directly into wudang Group groupadd wudang useradd -g wudang haikang
Modify user group
grammar : usermod -g User group user name case : Create a group mojiao hold haikang Put into mojiao Group instructions :groupadd mojiao
usermod -g mojiao haikang
User and group related files
/etc/passwd /etc/shadow /etc/group
<>Linux Group basic introduction

stay Linux Each user in must have a group attribute , Cannot be independent of the group . stay Linux Each file in the has an owner , All groups , Concept of other groups .

It means : A user must have a group to which he belongs , A file must have an owner ( Generally, who created this file ), All groups ( Creator's group ), Other groups ( Groups other than the creator's group )

* owner
* All groups
* Other groups
* Change the user's group
file , Directory owner

Usually the creator of the file , Who created the file , Naturally become the owner of the file .

View the owner of the file
grammar : ls -lahl ls -l ll

There are two connections because there are two connection points in the folder by default : ..

If it is an ordinary file connection 1, Default only :. ; In fact, they are all nodes .

Modify file owner : Modify owner is :chown
instructions : chown user name file name case : requirement : use root Create a file for apple.txt, Then change its owner to haikang touch
apple.txt chown haikang apple.txt
file , Directory group : Modification group is chgrp

When a user creates a file , The group of this file is the group of this user
see file , Directory group instructions : ls -ahl ls -l ll Application examples , use haikang User creates a file ok.txt, See which group the file attributes belong to ?
haikang ok.txt Modify the group where the file is located instructions : chgrp Group name file name Application examples :
use root User created file root.txt, See which group the current file attribute belongs to , Then put the group of this file , Modify to fruit group instructions : 1.groupadd fruit
2.touch root.txt 3.ll ( or ls -l or ls -ahl) 4.chgrp fruit root.txt
Other groups

Except for the owner of the file and the user in the group , Other users of the system are other groups of files

Change user group

When adding users , You can specify which group to add the user to , Same use root Administrative permissions can change the group of a user .

Change user group ( This group must exist )
1.usermod -g New group name user name 2.usermod -d Directory name user name
Change the initial directory where the user logs in . In particular : The user needs permission to enter the new directory , Otherwise, you can't log in after modification Application examples :
take haikang This user from the original group , Modify to myHaiKang group usermod -g myHaiKang haikang
<> Basic introduction to permissions
ls -l The contents displayed in the are as follows : drwxr-xr-x. 3 root fruit 16 Nov 24 06:10 AA 0-9 Bit description ( in total 10 position )
1. The first 0 Bit determines the file type (d - l c b) l Is a link , amount to Windows Shortcut to ( Hard links and soft links ) - It's a normal file
d It's a directory , Quite Windows Folder in c Is a character device file , mouse , keyboard b It's a piece of equipment , Such as hard disk
2. The first 1-3 Bit determination owner ( The owner of the file ) Have permissions for this file .---User 3. The first 4-6 Bit determines the group to which it belongs ( Same as user group ) Have permissions for this file .---Group
4. The first 7-9 Bit determines that other users have permissions on the file .Other
rwx Detailed explanation of authority ( a key )
rwx Act on file 1.[r] Represent readable (read): Can read , see
2.[w] Representative writable (write): Possible modification , However, it does not mean that the file can be deleted , To delete this file, you must be the holder 3.[x] Representative can execute (execute): Can be executed
rwx Action folder 1.[r]: Represent readable (read): Can read ,ls View directory contents
2.[w]: Representative writable (write): Can be modified , For files in the directory ( establish + delete + rename ) catalogue 3.[x]: Representative executable (execute): You can enter this directory
drwxr-xr-x. 3 root fruit 16 Nov 24 06:10 AA Can be expressed numerically as :r=4,w=2,x=1 because rwx=4+3+1=7
Other instructions : l file : Number of hard connections or directories : Number of subdirectories root user fruit group 16 file size ( byte ) Nov 24 03:10 AA file name
Modify permissions

adopt chmod instructions , You can modify the permissions of files or directories

chmod [-R] ijk file name ( there ijk Represents a number )

If you want to operate on a folder, you need to add "-R" Parameters are changed recursively

The first way :+ - = Change authority

u: owner g: owner o: someone else a: all (u,g,o Sum of )
case : 1: chmod u=rwx,g=rx,o=x file , Directory name 2: chmod o+w file , Directory name 3. chmod a-x file , Directory name
Case demonstration : 1: to ZS The owner of the file has permission to read, write, and execute , Read and execute permissions for the group , Give other read and execute permissions chmod u=rwx,g=rx,o=x zs chmod 751
zs 2. to ZS The owner of the file removes permission to execute , Increase group write permission chmod u-x,o+w zs 3. to ZS Add read permissions to all users of the file chmod a+r zs
The second way : Change permissions through numbers

r=4 w=2 x=1 rwx=7

chmod u=rwx g=rx o=x File directory name

amount to chmod 751
Case demonstration : requirement : take /home/abc.txt File permission modification rwxr-xr-x, It is realized by giving numbers : chmod 755 /home/abc.txt
Modify file ( Folder or directory ) owner

chown Command is used to change the master and group of a file , The syntax of this command operation is in the format :

grammar :

chown [-R] Account name [: Group name ] file name

If the file name is a directory , And require all files in the directory to be changed at the same time , You need to join "-R" Parameters are changed recursively , and chgrp If the method is modified, no parameters need to be added
Case demonstration : 1. Please /home/abc.txt The owner of the file is modified to haikang user chown haikang /home/abc.txt
2. Please /home/test The owner of all files and directories under the directory haikang user chown -R haikang /home/test
Modify file , Directory group

grammar :

chgrp [-R] Group name file name
Please /home/abc.txt The group of the file is modified to shaolin( Shaolin Temple ) groupadd shaolin chgrp shaolin abc.txt
Please /home/test All files in the directory and all groups of the directory are modified to shaolin chgrp -R shaolin /home/test
Instruction Summary
Add user :useradd user name

Change Password :passwd user name

delete user :userdel [-rf] user name

Query user information :id user name

Switch users :su - user name

Query current user login information :who am i / whoami

New group :groupadd [-g( Modify user group GID)/-n( Modify the group name of the user group )]

delete group :groupdel Group name

Modify user group :groupmod -g User group ( Group name ) user name

View the owner of the file :ls -lahl ls -l ll

Modify file owner , Modify the group of files :chown [-R] Account name [: Group name ] file name

chown It can be used to modify the owner and group

Modify the group to which the file belongs :chgrp [-R] Group name file name

Modify file permissions ( a key ):chmod [-R] ijk file name ( This is ijk It's a number )

Technology
©2019-2020 Toolsou All rights reserved,
evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possible Experiment 4 Automated test tools - software test mysql Export data sql sentence _mysql according to sql Query statement export data Create a thread ——— Javaweb (3) Data structure experiment ( three )—— Stacks and queues TS stay vue2 Writing in the project web Front end signature plug-in _signature_pad Plug in implements electronic signature function docker Where is the image stored Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control springboot How to get reality in ip address