Centos7新增用户并授权

一、创建新用户

1、创建一个新用户:prefma

[root@localhost ~]# adduser centos

2、为新用户创建初始化密码
格式 passwd 用户名

[root@localhost~]# passwd centos
Changing password for user centos.
New password:             # 输入密码
Retype new password:      # 再次输入密码
passwd: all authentication tokens updated successfully.

二、授权

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

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

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

[root@localhost~]# whereis sudoers                     # 查找sudoers文件路径
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz
[root@localhost~]# ls -l /etc/sudoers                  # 查看权限
-r--r----- 1 root root 3938 Sep  6  2017 /etc/sudoers  # 只有读权限
[root@localhost~]# chmod -v u+w /etc/sudoers           # 赋予读写权限
mode of ‘/etc/sudoers’ changed from 0440 (r--r-----) to 0640 (rw-r-----)

2、修改sudoers文件

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

root ALL=(ALL) ALL
centos ALL=(ALL) ALL #这个是新用户

然后输入命令 wq! 保存修改。
3、收回权限

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

4、新用户登录

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

[prefma@localhost~]$ pwd
/home/centos
[centos@localhost~]$ ls -l /etc/sudoers
-r--r----- 1 root root 3995 Oct 16 22:42 /etc/sudoers

参考文章地址:https://www.cnblogs.com/imyalost/p/9801426.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值