Centos 7下添加新用户并授权

1.创建一个 xiaoyang 用户

[root@VM_81_181_centos ~]# adduser xiaoyang

2.为创建的用户设置密码

[root@VM_81_181_centos ~]# passwd xiaoyang
Changing password for user xiaoyang.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
Sorry, passwords do not match.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

3.对创建的新用户进行sudo操作的授权

说明:sudo 命令是在sudoers文件中的

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

4.查看文件权限

[root@VM_81_181_centos ~]# ls -l /etc/sudoers
-r--r-----. 1 root root 3938 Jun  7  2017 /etc/sudoers

  

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

5.加入可写的权限

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

6.将xiaoyang用户添加至sudoers文件中

[root@VM_81_181_centos ~]# vi /etc/sudoers
## Allow root to run any commands anywher 
root ALL=(ALL) ALL 
admin ALL=(ALL) ALL

7.将sudoers文件权限改回去

[root@VM_81_181_centos ~]# chmod -v u-w /etc/sudoers

8.测试新用户xiaoyang进行登陆,使用su xiaoyang操作:

[root@VM_81_181_centos ~]# su xiaoyang
[xiaoyang@VM_81_181_centos root]$ 

  

转载于:https://www.cnblogs.com/leeyongbard/p/9513960.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值