首页 > 系统相关 >centos禁止root登录,新账户使用管理员权限

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

时间:2023-05-18 16:34:41浏览次数:31  
标签:username 登录 centos sudo 用户 提权 管理员 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

标签:username,登录,centos,sudo,用户,提权,管理员,root
From: https://www.cnblogs.com/gaoyanbing/p/17412348.html

相关文章

  • Linux Centos 7 磁盘扩容
    背景情况在使用Centos的时候,由于上传的附件越来越多。原有的磁盘空间不足以用来存储更多的附件。也不可能通过迁移系统的方式来改善这个问题。最优解的方式就是采取扩容磁盘的方式。准备工作操作系统:Centos7(其他Linux系统类似)其他:向系统添加一块或多块磁盘开始迁移查......
  • centos7+mariadb安装在线评判系统
    在线评判系统安装:https://gitee.com/yhssdl/lpszoj/blob/master/docs/install.md其他问题升级到php7.4https://blog.csdn.net/zhongliang415/article/details/108640682#:~:text=升级php到php7.4版本1安装版本库yuminstallepel-releaseyum-utils-y,php-gdphp-curlphp-......
  • Centos7搭建sftp
    Centos7搭建sftp根据网上教程写了总结写了个搭建的自动化脚本#!/bin/bashfunctioncheckVersion(){#获取SSH版本号#获取SSH版本信息version_info=$(ssh-V2>&1)#从版本信息中提取OpenSSH版本号openssh_version=$(echo"$version_info"|awk-F'[,_]''{p......
  • centos配置node环境
    下载安装包cd/usr/local/bin/wgethttps://cdn.npmmirror.com/binaries/node/latest-v16.x/node-v16.13.1-linux-x64.tar.xz解压压缩文件tar-xvfnode-v16.13.1-linux-x64.tar.xzyuminstallgccgcc-c++mvnode-v16.13.1-linux-x64Node.jsln-s/usr/local/bin/Node......
  • ubuntu 20.04 root 登录设置
    ubuntu20.04设置root默认登录1.设置root密码sudopasswdroot2.root用户编辑/etc/ssh/sshd_config文件vi/etc/ssh/sshd_config修改前:#PermitRootLoginprohibit-password修改后:PermitRootLoginyes3.重启ssh服务sudosystemctlrestartssh......
  • centos7 中安装 busco
     001、系统[root@PC1software]#cat/etc/redhat-releaseCentOSLinuxrelease7.9.2009(Core) 002、python版本[root@PC1software]#python3--versionPython3.11.3 003、gcc版本[root@PC1software]#gcc--versiongcc(GCC)4.8.520150623(RedHat......
  • CentOS7.7安装docker
    1.背景想自己部署一套halo,发现需要docker环境,而且docker现在已经用处广泛,所以在CentOS服务器上安装docker2.步骤#Uninstalloldversionssudoyumremovedocker\docker-client\docker-client-latest\docker-co......
  • centos系统安装docker
    ###yum源配置###wget-o/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo#wget、curl两种下载方式皆可wget-o/etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-7.repo curl-o/etc/yum.repos.d/CentOS-Base.repohttp......
  • CentOS下安装vncserver进行远程桌面控制
    CentOS下安装vncserver进行远程桌面控制yumgroupinstall-y"XWindowSystem""Desktop""ChineseSupport"yumgroupinstall-y"DesktopPlatform""DesktopPlatformDevelopment""Fonts""InternetBrowser&q......
  • CentOS系统的/tmp目录自动清理规则
    CentOS系统的/tmp目录自动清理规则1、CentOS7CentOS7下,系统使用systemd管理易变与临时文件,与之相关的系统服务有3个:systemd-tmpfiles-setup.service:CreateVolatileFilesandDirectoriessystemd-tmpfiles-setup-dev.service:Createstaticdevicenodesin/devsystemd-tmpf......