创建用户和初始化密码
# 创建新用户 joker
adduser joker
# 为 joker 用户初始化密码
passwd joker
授权
新创建的用户并不能使用sudo
命令,需要给他添加授权。
sudo
命令的授权管理是在 sudoers 文件里的。可以看看 sudoers:
[root@localhost ~]# sudoers
bash: sudoers: 未找到命令...
[root@localhost ~]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
找到这个文件位置之后再查看权限:
[root@localhost ~]# ls -l /etc/sudoers
-r--r----- 1 root root 4251 9月 25 15:08 /etc/sudoers
只有只读的权限,如果想要修改的话,需要先添加w权限:
[root@localhost ~]# chmod -v u+w /etc/sudoers
mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加内容了,在下面的一行下追加新增的用户:
[root@localhost ~]# vim /etc/sudoers
## Allow root to run any commands anywher
root ALL=(ALL) ALL
joker ALL=(ALL) ALL #这个是新增的用户
wq
保存退出,这时候要记得将写权限收回:
[root@localhost ~]# chmod -v u-w /etc/sudoers
mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
文档更新时间: 2021-09-20 12:55 作者:joker.liu