Linux basics-file management, user management, user permissions

------------------------------------------File Management------ -----------------------------

Linux directory structure
windows: organize files in a multi-root way C:\ D:
Linux: organize files in a single-root way /
Insert picture description here
bin: store command files
boot: store startup devices
dev: equipment, hardware
etc: store configuration files
home: users Home directory
root: home directory of root user
run: run directory
sbin: supermanagement command
tmp: temporary directory
usr: application directory
var: log, mail

Linux file types
-ordinary files (text files, binary files, compressed files, movies, pictures, etc.)
d directory files (blue)
b block device files
c character device files
l link files (light blue)
s socket files
p Pipeline file

**

---------------------------------User Management--------------- ----------------

User basic information file: /etc/passwd
root: x: 0: 0: root: /bin/bash
User name: x: uid: gid: description: HOME: shell

User password information file: /etc/shadow
username: password encryption value: last modification time: minimum time interval: maximum time interval

Group information file: /etc/group
root: x: 0:
group name: group password: group ID: group member

----------------------------------------------------------------------------

user

Create user: useradd user name
-u specify UID
-d specify home directory
-g specify user's basic group
-G specify user's additional group
modify password: passwd user name
query user basic information: id user name
delete user: userdel -r user
Modify user attributes by name : usermod
usermod -s /sbin/nologin username

----------------------------------------------------------------------------

group

Create a group: groupadd group name
/etc/passwd can view the user's basic group
/etc/group can view the user's additional group

Group member management: gpasswd
gpasswd -a user name group name#add a user to a group
gpasswd -d user name group name#delete a user in a group

----------------------------------------------------------------------------

Ordinary user escalation

1. Permanent elevation su
su-root # Need to know the password of the switching object
2. Temporary elevation sudo
a. Add the user who needs elevation to the wheel group.
useradd hulk -G wheel
#Add the user to the specified additional group when creating a user gpasswd -a hulk wheel #Add the existing user to the specified additional group
b. Add sudo before the command when executing a special command.
sudo userdel chen

--------------------------------User rights---------------- ----------------

Basic permissions UGO
Insert picture description here

Setting permissions

1. Change permissions chmod
chmod -R #Recursively change permissions, so that the files in the directory also change permissions
a. Use symbols
Object assigner permission type
u + r
g-w
o = x
a
chmod u+r file1
chmod ur file1
chmod u =r file1

b. Use the number
chmod 644 file1
6(rw): Owner
4 (r ): Group
4 (r ): Others
2. Change the file’s owner and group chown
a. Change the file’s owner chown chen file1
b . Change the file's belonging group chown .hr file1
a. Change the file's owner, array chown chen.hr file1

----------------------------------------------------------------------------

Basic permission ACL

Syntax:
increase file permissions: setfacl -mu:user01:rwx /home/file1
view file permissions: getfacl /home/file1
delete file ACL permissions: setfacl -xu:alice /home/file1
delete all ACL permissions of files: setfacl -b /home/file1

----------------------------------------------------------------------------

Special permission

1. Special bit suid : when suid is for a file/program, it has the permission to temporarily obtain the owner
chmod u+s /usr/bin/cat
When the file has the s permission, other users will get the owner of the file when using the file The same permissions.

2. File attribute chattr : Set the file attribute, which can be
changed
for all users, including root chattr. Change the file attribute lsattr. View the file attribute
chattr +a file1 # Make file1 only write to
chattr +i file1 # No modification is allowed

3. Process mask umask
The default permissions of newly created files and directories will be affected by umask. umask indicates the permissions to be subtracted. (Temporary)
umask #View mask

Guess you like

Origin blog.csdn.net/weixin_43670190/article/details/107969442