您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Linux的账号与权限管理方法是什么
## 引言
在Linux操作系统中,账号与权限管理是系统安全的核心组成部分。作为多用户操作系统,Linux通过完善的账号体系和细粒度的权限控制机制,确保不同用户既能完成各自的工作,又不会越权访问敏感资源。本文将深入解析Linux账号体系架构、权限管理模型、核心配置文件及实用管理工具,并附赠企业级实践方案与安全加固建议。
## 一、Linux账号管理体系
### 1.1 用户账号类型
#### 系统用户(System Users)
- 服务账户:如`apache`、`mysql`等,UID范围通常为1-999(RHEL系)或101-999(Debian系)
- 特殊权限账户:如`root`(UID 0)、`nobody`(UID 65534)
#### 普通用户(Regular Users)
- 交互式登录账户,UID起始值:
- RHEL/CentOS:1000+
- Ubuntu/Debian:1000+
- 通过`/etc/login.defs`中的`UID_MIN`定义
### 1.2 用户组体系
#### 主要组(Primary Group)
```bash
# 创建用户时自动生成同名组
useradd -m testuser # 生成testuser组
usermod -aG wheel,developers testuser # 添加用户到附加组
wheel
:sudo权限组(RHEL系)sudo
:同wheel组(Debian系)docker
:容器管理组username:x:UID:GID:comment:homedir:shell
x
占位符,密码实际存储在/etc/shadow
$6$salt$hashed:18000:0:99999:7:::
$1
:MD5$5
:SHA-256$6
:SHA-512groupname:x:GID:member1,member2
-rwxr-xr-- 1 user group 4096 Jun 10 10:00 file.txt
││┌┐┌┐┌┐
│││││││└─ Other: Read
│││││└── Group: Execute
│││└─── Group: Read
│└──── Owner: Write/Execute
└───── File Type (-/d/l)
chmod 755 script.sh # 数字模式
chmod u+x,g-w,o-r file # 符号模式
权限位 | 作用 | 设置方法 |
---|---|---|
SUID | 执行时临时获取所有者权限 | chmod u+s /usr/bin/passwd |
SGID | 目录下新建文件继承组权限 | chmod g+s /shared_dir |
Sticky | 仅文件所有者可删除 | chmod o+t /tmp |
setfacl -m u:john:rwx /project/docs
setfacl -Rm g:devteam:r-x /src
getfacl /project/docs
# OUTPUT:
# user::rwx
# user:john:rwx
# group::r-x
# group:devteam:r-x
# mask::rwx
# other::r-x
useradd -m -s /bin/bash -G developers,sudo \
-c "Dev User" -u 1501 devuser
passwd -n 7 -x 90 -w 14 devuser # 最短7天,最长90天,提前14天警告
# 解决新建文件默认组不对的问题
chmod g+s /project
find /project -type d -exec chmod 2775 {} \;
# users.txt格式:
# username:passwd:UID:GID:comment:homedir:shell
newusers users.txt
echo "user1:NewPass123" | chpasswd -c SHA512
[domain/example]
ldap_uri = ldap://ldap.example.com
ldap_search_base = dc=example,dc=com
ldap_user_search_base = ou=People,dc=example,dc=com
auditctl -a always,exit -F arch=b64 -S execve -F euid=0
#!/bin/bash
# 检查SUID/SGID文件变化
find / -type f \( -perm -4000 -o -perm -2000 \) > /var/log/suid_check_$(date +%F).log
chattr +i /etc/passwd /etc/shadow
minlen = 12
dcredit = -1
ucredit = -1
ocredit = -1
lcredit = -1
grep user /etc/passwd
确认账号存在passwd -S user
检查密码状态usermod -U user
解锁被锁账户/etc/security/access.conf
限制# 模拟用户运行命令
sudo -u testuser ls /restricted
namei -l /path/to/file # 显示路径上所有节点的权限
完善的账号与权限管理是Linux系统安全的基石。通过合理规划用户/组体系、精确控制文件权限、实施必要的安全策略,可以构建既灵活又安全的系统环境。建议结合企业实际需求,制定符合合规要求的权限管理规范,并定期进行权限审计与漏洞扫描。
最佳实践提示:对于生产环境,建议实施最小权限原则(PoLP),所有账号只赋予完成工作所必需的最小权限集。 “`
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。