Centos 限制root帐户登陆ssh并配置指定帐户可以使用sudo命令

本文介绍如何在Centos系统中禁止root账户通过SSH登录,并配置指定账户使用sudo命令。首先通过修改sshd_config文件来阻止root远程SSH登录,然后重启SSH服务进行配置生效验证。接着为特定账户配置sudo权限,使其能够执行管理员级别的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Centos 限制root帐户登陆ssh并配置指定帐户可以使用sudo命令

一,禁止root登陆ssh

useradd shiyy       #添加帐户
echo "shiyy01"| passwd shiyy --stdin    #设置帐户密码

vi /etc/ssh/sshd_config      #编辑ssh服务配置文件
将这一行#PermitRootLogin yes
改为 PermitRootLogin no

/etc/init.d/sshd restart     #重启服务

 

登陆root测试结果:无法登陆
login as: root
root@192.168.105.128's password:
Access denied
root@192.168.105.128's password:
Access denied
root@192.168.105.128's password:
Access denied
root@192.168.105.128's password:
Access denied
root@192.168.105.128's password:

登陆shiyy测试结果:登陆正常

login as: shiyy
shiyy@192.168.105.128's password:
Last login: Sat Apr 13 02:52:33 2013 from 192.168.105.1
[root@Cgate ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  iptables.rules

 

二,指定帐户使用sudo切换到root

切换到root权限编辑sudo配置文件
vi /etc/sudoers
在这一行后
root    ALL=(ALL)       ALL
添加帐户
shiyy   ALL=(ALL)       ALL

找到这两行取消#号

 %wheel ALL=(ALL)       ALL  #用sudo命令时提示输入密码
 %wheel ALL=(ALL)       NOPASSWD: ALL #以群组的形式管理帐户 

测试shiyy帐户使用sudo
直接用 vi /etc/sudoers编辑这个配置文件是什么也看不到的,因为没有权限
用苏do命名测试编辑ok!
[shiyy@Cgate ~]$ sudo vi /etc/sudoers
[sudo] password for shiyy:
[shiyy@Cgate ~]$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值