1. Operation commands for users
- sudo adduser username //create user
- sudo cat /etc/shadow //View all users
- sudo usermod -l new user name old user name // modify user name
- su username //enter user
- id //View user UID and GID
- sudo userdel username //delete user
2. User group commands
-
sudo groupadd -g 800 User group name //Add user group whose GID is 80
-
cat /etc/group //View all user groups
-
gpasswd -a user name user group name // add users to the user group
-
sudo userdel user group name //delete user group
3. View file permissions
- ls -l //View file attributes
It will display such as: drwxr-xr-x 2 lkw use 4096 12-10 18:30 Documents
corresponding respectively: file attribute connection number file owner group file size file modification time file name
In the file attributes:
if the first one is [ d ], it represents a directory
. If the first one is [ - ], it represents a file. The
next three are a group , which are
the permissions of the file owner and the permissions of the user group to which the file belongs . Other people's permissions on this file
[ r ] stands for readable (read)
[ w ] stands for writable (write)
[ x ] stands for executable (execute)
4. Modify file permissions
chmod syntax: chmod [-optional parameter][<permission range>+/-/=<permission setting>] file/directory
(1) Specify a certain type of user:
chmod [u/g/o/a] [+/-/=] [r/w/x] file
Parameter explanation:
[u/g/o/a] is the scope of authority, where:
u: User, the owner of the file or directory
g: Group, the group to which the file or directory belongs
o: Other, except for the file or directory owner and the group to which they belong, other users belong to this range
a: All, that is All users
Permission operation:
+ means adding permission
-means canceling permission
= means canceling the previous permission and giving the only permission
Permission code:
r: read permission, the digital code is "4"
w: write permission, the digital code is "2"
x: execute permission, the digital code is "1"
-: does not have any permissions, the digital code is "0" "
File, file name (path)
(2) Specify the permissions of three types of users at the same time: chmod [xyz] file
Among them, x, y, and z specify the permissions of User, Group, and Other respectively; three binary numbers are used to represent the three permissions of "r, w, x" (note the order),
where 0 means no permission, and 1 means permission. For example, 100 means that there is'r' authority but no "wx" authority; and
then the three-digit binary number is converted to decimal, it is the value of x (or y, z).
For example:
sudo chmod 774 test.txt
User: 7 = 111 means "r, w, x" permission
Group: 7 = 111 means "r, w, x" permission
Other: 4 = 100 means only "r" permission, but no "w,x" Authority