centos su sudo wheel

时间:2022-07-25
本文章向大家介绍centos su sudo wheel,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

为加强系统账户安全性,对系统及账户权限进行加固。修改ssh 服务端口号,禁止root账户远程登录,普通用户使用秘钥文件登录服务器后使用sudo 赋予完全的 root 权限。

禁用root登录

PermitRootLogin 限定root用户通过ssh的登录方式,如禁止登陆、禁止密码登录、仅允许密钥登陆和开放登陆。(默认为yes)

cat /etc/ssh/sshd_config |grep  PermitRootLogin
PermitRootLogin no

PermitRootLogin 参数

参数类别

是否允许ssh登陆

登录方式

交互shell

yes

允许

没有限制

没有限制

without-password

允许

除密码以外

没有限制

forced-commands-only

允许

仅允许使用密钥

仅允许已授权的命令

no

不允许

N/A

N/A

禁止密码登录

PasswordAuthentication 是否允许密码登录,默认为yes。AWS 云主机默认为no。

cat /etc/ssh/sshd_config |grep PasswordAuthentication
PasswordAuthentication no

ssh 服务端口

ssh 服务默认端口 22 修改默认端口2222

cat /etc/ssh/sshd_config  |grep Port
Port 2222

sudoers 文件

把用户加入 wheel 组中,就可以sudo -s 切换到root。用户赋予完全的 root 权限而不用提供 root 密码。

vi /etc/sudoers
centos    ALL=(ALL)       ALL
#centos用户执行sudo命令(需要输入密码)
centos    ALL=(ALL)      NOPASSWD: ALL
#centos用户执行sudo命令(不需要输入密码)
%wheel   ALL=(ALL)       ALL
#%wheel 组中用户执行sudo命令(需要输入密码)
%wheel   ALL=(ALL)       NOPASSWD: ALL
#%wheel 组中用户执行sudo命令(不需要输入密码)

将用户添加到wheel

usermod  -G wheel centos

查看用户组

id centos 
groups centos

撤销用户附加wheel组(修改/etc/group文件)

gpasswd

sudo gpasswd -d centos wheel

修改/etc/group文件

sed -i 's#wheel:x:10:centos#wheel:x:10:#g' /etc/group

只有wheel组用户能够su

用户在wheel组下才能su root

vim /etc/pam.d/su
#取消auth required pam_wheel.so use_uid注释
auth required pam_wheel.so use_uid
#修改/etc/login.defs 文件
 echo “SU_WHEEL_ONLY yes” >> /etc/login.defs