美文网首页
centos 创建普通用户,并添加sudo权限

centos 创建普通用户,并添加sudo权限

作者: 彩色的炮灰 | 来源:发表于2023-07-04 14:34 被阅读0次

一、创建新用户
1、创建一个新用户:test
[root@localhost ~]# adduser test
2、为新用户创建初始化密码

[root@node04 ~]# passwd test
更改用户 test 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

image.png

二、授权
个人用户的权限只可以在本home下有完整权限,其他目录需要别人授权。经常需要root用户的权限,可以通过修改sudoers文件来赋予权限。

新创建的用户并不能使用sudo命令,需要给他添加授权。

1、查找sudoers文件路径并赋予权限

[root@node04 ~]# whereis sudoers    # 查找sudoers文件路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
[root@node04 ~]# ls -l /etc/sudoers    # 查看权限
-r--r-----. 1 root root 4328 9月  30 2020 /etc/sudoers    # 只有读权限
[root@node04 ~]# chmod -v u+w /etc/sudoers    # 赋予读写权限
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)

image.png

2、修改sudoers文件
输入命令 vim /etc/sudoers 修改sudoers文件,添加新用户信息:

# Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
test    ALL=(ALL)     ALL #这个是新用户

然后输入命令 wq! 保存修改。


image.png

3、收回权限

[root@node04 ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)

image.png

4、新用户登录

新建连接,使用新创建的用户登录,并进行验证,比如:

[test@node04 ~]$ pwd
/home/test
[test@node04 ~]$  ls -l /etc/sudoers
-r--r-----. 1 root root 4356 7月   5 16:11 /etc/sudoers

相关文章

网友评论

      本文标题:centos 创建普通用户,并添加sudo权限

      本文链接:https://www.haomeiwen.com/subject/rsqhudtx.html