CentOS 7中添加新用户并授权

(一)创建一个admin用户

[root@xxxx home]# adduser admin

没有内容输出,在linux下说明操作正确

(二)为admin用户设置密码

[root@xxxx home]# passwd admin
Changing password for user admin.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

(三)对新admin用户进行sudo操作的授权

因为sudo命令是在sudoers文件中的,我们看一下sudoers文件

[root@xxxx home]# sudoers
-bash: sudoers: command not found

(四) 查找sudoers文件所在

[root@xxxx home]# whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz

(五)查看一下文件的权限

[root@xxxx home]# ls -l /etc/sudoers
-r--r----- 1 root root 3938 Sep 6 2017 /etc/sudoers

可以看到只有只读的权限,这时候我们要加入一个可写的(w)的权限

(六)加入可写的权限

[root@xxxx home]# chmod -v u+w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)

 

(七)把admin用户添加到sudoers中
 

[root@xxxx home]# vi /etc/sudoers

然后找出下方的信息>>## Allow root to run any commands anywher 并在其下方插入admin用户的权限

## Allow root to run any commands anywher 
root ALL=(ALL) ALL 
admin ALL=(ALL) ALL #新增admin用户

(八)按CTRL+C然后wq!回车保存,然后把sudoers文件权限改回去,毕竟这是一个重要的文件

[root@xxxx home]# chmod -v u-w /etc/sudoers
mode of ‘/etc/sudoers’ changed from 0640 (rw-r-----) to 0440 (r--r-----)

(九)测试新用户admin进行登陆,使用su admin操作:
 

[root@xxxx admin]# su admin
[admin@xxxx ~]$

 

到此,新增admin并且授权sudo就完成了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值