centos添加用户和增加用户root权限

  |   0 评论   |   0 浏览

1、添加用户

#adduser me  //添加一个名为me的用户
#passwd me   //修改密码
Changing password for user me.
New UNIX password:         //在这里输入新密码
Retype new UNIX password:  //再次输入新密码
passwd: all authentication tokens updated successfully.

2、赋予root权限

请先切换到超级用户(root),将 /etc/sudoers 修改为可编辑。

chmod 777 /etc/sudoers

对此文件进行修改后,将 /etc/sudoers 修改回只读模式。

chmod 440 /etc/sudoers

方法一: 修改 /etc/sudoers 文件,找到下面一行,把前面的注释(#)去掉

## Allows people in group wheel to run all commands
%wheel    ALL=(ALL)    ALL
// 然后修改用户,使其属于root组(wheel),命令如下:
#usermod -g root me
// 修改完毕,现在可以用me帐号登录,然后用命令 su – ,即可获得root权限进行操作。

方法二: 修改 /etc/sudoers 文件,找到下面一行,在root下面添加一行,如下所示:

## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
me   ALL=(ALL)     ALL
// 修改完毕,现在可以用me帐号登录,然后用命令 sudo – ,即可获得root权限进行操作。

方法三: 修改 /etc/passwd 文件,找到如下行,把用户ID修改为 0 ,如下所示:

me:x:0:33:me:/data/webroot:/bin/bash

3、禁止root远程登陆

vim /etc/ssh/sshd_config
找到 # PermitRootLogin yes
改为 PermitRootLogin no

4、禁用本地root用户(root用户本地还是远程都无法使用,谨慎操作)

编辑/etc/pam.d/login文件,增加如下一行
auth required pam_succeed_if.so user != root quiet

5、修改ssh端口

vim /etc/ssh/sshd_config
#Port 22字段删掉#,将22改为其他不被使用的端口

6、重启服务

systemctl restart sshd.service


标题:centos添加用户和增加用户root权限
作者:zytops
地址:https://www.zytops.com/articles/2023/02/20/1676874689236.html