centos7下创建新用户并授权

开发十年,就只剩下这套Java开发体系了 >>>   hot3.png

1、创建新用户

    创建一个用户名为:test

adduser test

    创建初始密码:

passwd test

2、授予root权限

    个人用户的权限只可以在/home/test下有完整权限,其他目录要看别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。新创建的用户并不能使用sudo命令,需要给他添加授权。

    sudo命令的授权管理是在sudoers文件里的。查找sudoers

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

    找到这个文件位置之后再查看权限

[root@iZm5e3d4r5i5ml889vh6esZ local]# ls -l /etc/sudoers
-r--r----- 1 root root 3985 Jun 19 11:25 /etc/sudoers

    修改权限,使其可以修改

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

    添加新增用户test

## Next comes the main part: which users can run what software on 
## which machines (the sudoers file can be shared between multiple
## systems).
## Syntax:
##
##      user    MACHINE=COMMANDS
##
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
test    ALL=(ALL)       ALL

    收回写权限

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

    第一次使用sudo会提示你,你已经具有root权限,身负责任。而且需要输入密码才可以下一步。如果不想需要输入密码怎么办,将最后一个ALL修改成NOPASSWD: ALL

猜你喜欢

转载自blog.csdn.net/xixingzhe2/article/details/82833771