建立一个用户名为:testbash
adduser test
建立初始密码:spa
passwd test
我的用户的权限只能够在/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: ALL
。test