centos7下建立新用戶並受權

一、建立新用戶

    建立一個用戶名爲:testbash

adduser test

    建立初始密碼:spa

passwd test

二、授予root權限

    我的用戶的權限只能夠在/home/test下有完整權限,其餘目錄要看別人受權。而常常須要root用戶的權限,這時候sudo能夠化身爲root來操做。新建立的用戶並不能使用sudo命令,須要給他添加受權。3d

    sudo命令的受權管理是在sudoers文件裏的。查找sudoerscode

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

    找到這個文件位置以後再查看權限ip

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

    修改權限,使其能夠修改it

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

    添加新增用戶testio

## 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

    收回寫權限class

[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: ALLtest

相關文章
相關標籤/搜索