centos禁止root登录,新账户使用管理员权限

背景:为了提供更安全可靠的外网ssh连接,计划对root用户登录做限制,停止root用户登录,使用新账号登录,可有效减小黑客入侵几率,不仅需要猜密码,还需要先猜账号,无疑大大增加入侵成本。

服务器版本:centos7.6

步骤一,新增用户username
# useradd username //username 为想要创建的用户名
# passwd username //修改密码
步骤二,新用户添加管理员权限
方法一:将用户加入 wheel 组
1.首先确保文件 /etc/sudoers 中,这行代码未被注释。

107%wheel ALL=(ALL) ALL
2.然后执行命令。

[root@a ~]# usermod -g wheel username
以用户 username 登录系统,使用 sudo 命令来提权,提权时需输入 username 的密码,默认情况下,一次提权有5分钟有效期。

或使用sudo -i 命令切换到root用户

[username@a ~]$ sudo yum install httpd

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password username:
ps:如遇到root可执行但新账户无法执行的命令,可使用su - 命令 输入root密码后操作即可
方法二:单独设置用户权限
1.编辑文件 /etc/sudoers ,找到如下代码:

100root ALL=(ALL) ALL
在底下增加一行:

101 username ALL=(ALL) ALL
保存后退出。

使用效果与将用户加入 wheel 组一样。如将代码改为:

[root@a ~]# username ALL=(ALL) NOPASSWD:ALL
则 sudo 时不输入 exampleuser 的密码也可提权。

步骤三,禁止root登录
# vim /etc/ssh/sshd_config
在PermitRootLogin 这一行改变为如下 (yes改为no)

xxxx
PermitRootLogin no
xxxx
步骤四,重新加载sshd配置文件
# systemctl reload sshd.service
————————————————
版权声明:本文为CSDN博主「马搏士」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42517271/article/details/128033154

posted @   GaoYanbing  阅读(106)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示