当前位置:网站首页>Users, groups, and permissions
Users, groups, and permissions
2022-07-07 12:56:00 【LC181119】
1.Linux Security model
resource allocation :
- Authentication: authentication , Verify user identity
- Authorizaation: to grant authorization , Different users set different permissions
- Accounting | Audition: Audit
1.1 user
Linux Each user in is through User Id (UID) To uniquely identify
- Administrators :root,0
- Ordinary users :1-60000 Automatically assigned
- System users :1-499(CentOS 6 before ),1-999(CentOS 7 in the future )
Allocate permissions to the resources obtained by the daemon
- The logged in user :500+ (CentOS 6 before ),1000+ (CentOS 7 in the future )
Interactive login for users
1.2 User group
- Administrators group :root, 0
- The normal group :
- System group :1-499(CentOS 6 before ), 1-999(CentOS7 in the future ), Divide the permissions of the daemon to obtain resources with
- The normal group :500+(CentOS 6 before ), 1000+(CentOS7 in the future ), For users
1.3 The relationship between users and groups
- The primary group of users (primary group): Users must belong to one and only one main group , By default, users will be created automatically A group with the same name as the user name , As the primary group of users , Because there is only one user in this group , Also known as private group
- Additional groups for users (supplementary group): A user can belong to zero or more secondary groups , Affiliate group
1.4 Security context
2. User and group profiles
2.1 Primary profiles for users and groups
- /etc/passwd: User and its attribute information ( name 、UID、 The main group ID etc. )
- /etc/shadow: User password and its associated attributes
- /etc/group: Group and its attribute information
- /etc/gshadow: Group passwords and their associated attributes
2.2passwd File format
2.3shadow File format
authconfig --passalgo=sha256 --update
- Long enough
- Using a digital 、 Capital 、 At least... In lowercase letters and special characters 3 Kind of
- Use random passwords
- Replace regularly , Don't use passwords that have been used recently
2.4group File format
2.5gshdow File format
2.6 Document operation
- vipw and vigr
- pwck and grpck
3. User and group management commands
- useradd
- usermod
- userdel
- groupadd
- groupmod
- groupdel
3.1 The user to create
useradd Command can create new Linux user
useradd [options] LOGIN
-u UID-o coordination -u Options , Do not check UID Uniqueness-g GID Specifies that the user belongs to the base group , A group name , It's fine too GID-c "COMMENT“ User's comment information-d HOME_DIR In the specified path ( non-existent ) Catalog for home-s SHELL Indicate the user's default shell Program , The available list is /etc/shells In file-G GROUP1[,GROUP2,...] Specify additional groups for users , The group must exist in advance-N Do not create private group as master group , Use users Group is the main group-r Create system user CentOS 6 Before : ID<500,CentOS7 in the future : ID<1000-m Create a home directory , For system users-M Do not create a home directory , For non system users-p Specify the encrypted password
3.2 User property modification
usermod [OPTION] login
-u UID: new UID-g GID: New main group-G GROUP1[,GROUP2,...[,GROUPN]]]: New additional group , The original additional group will be covered ; If you keep the original , At the same timeuse -a Options-s SHELL: New default SHELL-c 'COMMENT': New notes-d HOME: The new home directory will not be created automatically ; To create a new home directory and move home data , Use at the same time -m Options-l login_name: New name-L: lock Designated user , stay /etc/shadow The addition of password column !-U: unlock Designated user , take /etc/shadow Code bar ! Remove-e YYYY-MM-DD: Specify the expiration date of the user account-f INACTIVE: Set an inactive period , That is, the grace period
3.3 Delete user
userdel [OPTION]... Login
-f, --force mandatory-r, --remove Delete user home directory and mailbox
3.4 View user related ID Information
id [OPTION]... [USER]
u: Show UID-g: Show GID-G: Displays the... Of the group to which the user belongs ID-n: The display name , Need to cooperate ugG Use
3.5 Switch users or execute commands as other users
su [options...] [-] [user [args...]]
-l --login su -l UserName amount to su - UserName-c, --command <command> pass a single command to the shell with -c
- su UserName: Non login switch , That is, the configuration file of the target user will not be read , Do not change the current working directory , That is, incomplete switching
- su - UserName: Login switch , Will read the profile of the target user , Switch to your home directory , That is, complete switching
su [-] UserName -c 'COMMAND'
3.6 Set the password
passwd [OPTIONS] UserName
-d: Delete the specified user password-l: Lock the specified user-u: Unlock the specified user-e: Force user to change password next time login-f: Force operation-n mindays: Specify the minimum service life-x maxdays: Maximum service life-w warndays: How many days in advance to start warning-i inactivedays: Period of inactivity--stdin: Receive user password from standard input ,Ubuntu No such option
3.7 Change user password policy
chage [OPTION]... LOGIN
-d LAST_DAY # Time to change password-m --mindays MIN_DAYS-M --maxdays MAX_DAYS-W --warndays WARN_DAYS-I --inactive INACTIVE # Grace period after password expiration-E --expiredate EXPIRE_DATE # User's validity period-l Show password policy
3.8 Other user related commands
- chfn Specify personal information
- chsh Appoint shell, amount to usermod -s
- finger You can view the user's personal information
3.9 Create group
groupadd [OPTION]... group_name
Common options :
-g GID To specify GID Number ;[GID_MIN, GID_MAX]-r Create system group ,CentOS 6 Before : ID<500,CentOS 7 in the future : ID<1000
3.10 Modify the set of
groupmod [OPTION]... group
-n group_name: New name-g GID: new GID
3.11 groups deleting
groupdel [options] GROUP
-f, --force Mandatory deletion , Even the user's primary group is forced to delete the group , However, users without a primary group will be unavailable and unable to log in
3.12 Change group password
gpasswd [OPTION] GROUP
-a user take user Add to specified group-d user Removes the user from the specified additional group user-A user1,user2,... Set the list of users with administrative rights
3.13 Temporarily switch main group
newgrp [-] [group]
3.14 Change and view group members
groupmems [options] [action]
-g, --group groupname # Change to the specified group ( Only root)-a, --add username # Specify the user to join the group-d, --delete username # Remove user from group-p, --purge # Clear all members from the group-l, --list # Displays a list of group members
# View the user's group list
groups [OPTION].[USERNAME]...
4. File permission management
4.1 File owner and group attribute operation
4.1.1 Set the owner of the file chown
chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
OWNER # Only modify the ownerOWNER:GROUP # Modify the owner and group at the same time:GROUP # Modify only the group , Colons are also available . Replace--reference=RFILE # Refer to the specified properties , To modify the-R# recursive , Use this option with caution , Very dangerous !
4.1.2 Set the group information of the file chgrp
chgrp [OPTION]... GROUP FILE...
chgrp [OPTION]... --reference=RFILE FILE...
4.2 File permissions
4.2.1 File permission description
owner Belong to , ugroup Generic group , gother other , o
The final authority of the user , It's order matching from left to right , namely , owner , Subordinate to the group , others , Once the permissions are matched, they take effect immediately , No more toRight view its permissionsr and w Permission pair root Invalid userAs long as the owner , Group or other One of the three is x jurisdiction ,root You can execute
r Readablew Writablex eXcutable
r You can use file view class tools , such as :cat, You can get its contentw It can be modifiedx You can request the kernel to start this file as a process , That is, it can be executed ( function ) This file ( The contents of this file must be executable )
r have access to ls View in this directoryFile listw You can create files in this directory , You can also delete files in this directory , It has nothing to do with the permission of the deleted filex Sure cd Enter this directory , have access to ls -l View the file metadata in this directory ( Must cooperate with r jurisdiction ), Minimum accessible permissions belonging to the directoryX Just give the catalog x jurisdiction , Do not give files without execution permission x jurisdiction
4.2.2 Modify file permissions chmod
chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
# Reference resources RFILE File permissions , take FILE It is the same as RFILE
chmod [OPTION]... --reference=RFILE FILE...
4.3 Default permissions for new files and directories
- Default permissions for new files : 666-umask, If a bit of the result exists, execute ( Odd number ) jurisdiction , Then its permissions +1, accidentally The number remains the same
- Default permissions for new directories : 777-umask
umask
# Display in mode
umask –S
# The output can be called
umask –p
modify umask
umask #
- Global settings : /etc/bashrc
- User Settings :~/.bashrc
4.4 Linux Special permissions on the file system
- SUID Act on binary executables , The user will inherit the rights of the owner of this program
- SGID
- STICKY Act on the directory , Files in this directory can only be deleted by the owner
4.4.1 Special privileges SUID
- Can any executable program file be started as a process , It depends on whether the initiator has execution rights to the program file
- After starting as a process , The owner of the process is the initiator , The group of the process is the group of the initiator
- Permissions for a process to access a file , It depends on the initiator of the process
- Can any executable program file be started as a process : It depends on whether the initiator has execution rights to the program file
- After starting as a process , The owner of the process is the owner of the original program file
- SUID Valid only for binary executables
- SUID Setting on the directory makes no sense
chmod u+s FILE...
chmod 4xxx FILE
chmod u-s FILE...
4.4.2 Special privileges SGID
- Can any executable program file be started as a process : It depends on whether the initiator has execution rights to the program file
- After starting as a process , The process belongs to the original program file
SGID Permission setting :
chmod g+s FILE...
chmod 2xxx FILE
chmod g-s FILE...
chmod g+s DIR...
chmod 2xxx DIR
chmod g-s DIR...
4.4.3 Special privileges Sticky position
chmod o+t DIR...
chmod 1xxx DIR
chmod o-t DIR...
4.4.4 Special authority digital method
000 0001 1010 2011 3100 4101 5110 6111 7
4.5 Set file special properties
chattr +i file
chattr +a file
lsattr
4.6 Access control list ACL
4.6.1 ACL Authority function
owner , Custom user , Subordinate to the group | Custom groups , others
4.6.2 ACL Relevant command
- mask Only affect owners and other Maximum permissions for people and groups other than
- mask After logical and operation with the user's permission , To become a limited authority (Effective Permission)
- User or group settings must exist in mask It will take effect only when the permission is set
4.6.3 Backup and restore ACL
边栏推荐
- Enterprise custom form engine solution (XII) -- experience code directory structure
- 通讯协议设计与实现
- Creation and assignment of graphic objects
- JS to convert array to tree data
- leetcode刷题:二叉树23(二叉搜索树中的众数)
- Layer pop-up layer closing problem
- 怎样重置火狐浏览器
- 【从 0 开始学微服务】【01】什么是微服务
- Several ways to clear floating
- leetcode刷题:二叉树20(二叉搜索树中的搜索)
猜你喜欢
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
图像像素读写操作
NPM instal reports agent or network problems
2022a special equipment related management (boiler, pressure vessel and pressure pipeline) simulated examination question bank simulated examination platform operation
Sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
Day-15 common APIs and exception mechanisms
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
【无标题】
Cookie
明星企业普渡科技大裁员:曾募资超10亿 腾讯红杉是股东
随机推荐
[statistical learning method] learning notes - logistic regression and maximum entropy model
Leetcode skimming: binary tree 22 (minimum absolute difference of binary search tree)
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Leetcode brush question: binary tree 24 (the nearest common ancestor of binary tree)
Day-17 connection set
2022 practice questions and mock examination of the third batch of Guangdong Provincial Safety Officer a certificate (main person in charge)
Realize a simple version of array by yourself from
- Oui. Migration entièrement automatisée de la Sous - base de données des tableaux d'effets sous net
怎样重置火狐浏览器
test
详解ThinkPHP支持的URL模式有四种普通模式、PATHINFO、REWRITE和兼容模式
《ASP.NET Core 6框架揭秘》样章[200页/5章]
ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
What if does not match your user account appears when submitting the code?
云检测2020:用于高分辨率遥感图像中云检测的自注意力生成对抗网络Self-Attentive Generative Adversarial Network for Cloud Detection
Leetcode skimming: binary tree 27 (delete nodes in the binary search tree)
JS to convert array to tree data
【从 0 开始学微服务】【00】课程概述
About IPSec