在Ubuntu系统中,通过SSH进行权限管理主要涉及以下几个方面:
sudo adduser username
sudo deluser username
sudo passwd username
文件和目录权限:
使用chmod命令来更改文件或目录的权限。
chmod 755 file:设置文件为可读、可写、可执行(所有者),可读、可执行(组和其他用户)。chmod 644 file:设置文件为可读、可写(所有者),可读(组和其他用户)。特殊权限:
chmod u+s file:设置SUID位,使文件在执行时以文件所有者的权限运行。chmod g+s directory:设置SGID位,使目录中的新文件继承目录的组。编辑SSH配置文件:
sudo nano /etc/ssh/sshd_config
修改以下参数:
PermitRootLogin no:禁止root用户直接登录。PasswordAuthentication yes/no:启用或禁用密码认证。AllowUsers username1 username2:指定允许登录的用户。DenyUsers username1 username2:指定拒绝登录的用户。重启SSH服务:
sudo systemctl restart sshd
sudo visudo
username ALL=(ALL:ALL) ALL
这条规则允许username用户在所有主机上以所有用户的身份执行所有命令。SELinux: Ubuntu默认不启用SELinux,但如果安装了,可以通过以下命令管理:
sudo setenforce 0  # 临时禁用SELinux
sudo setenforce 1  # 永久启用SELinux
AppArmor: AppArmor是Ubuntu的另一种安全模块,可以通过以下命令管理:
sudo aa-enforce /etc/apparmor.d/usr.sbin.sshd
sudo tail -f /var/log/auth.log
通过以上步骤,你可以有效地管理Ubuntu系统中的SSH权限,确保系统的安全性和稳定性。