3.7su命令
用来切换用户 su - xiang 切换到xiang用户下 以某一个用户身份去执行某一命令
1[root@localhost text]# ls 2111 1.txt 2.txt 3[root@localhost text]# su - -c "touch /text/12.txt" xpf #以xpf用户去在制定路径下创建文件 4[root@localhost text]# ls -l 5总用量 8 6drwxr-Sr--. 3 root xiang1 30 3月 29 22:58 111 7-rw-rw-r--. 1 xpf xpf 0 4月 7 01:56 12.txt 8-rwxr--r--. 1 root root 39 4月 7 01:37 1.txt 9-rwxr--r--. 1 root root 846 3月 27 22:42 2.txt
3.8sudo命令
让A用户临时以B用户的权限去执行某一些操作
1visudo 2root ALL=(ALL) ALL 3xpf ALL=(ALL) /bin/ls,/bin/cd 4xiang1 ALL=(ALL) NOPASSWD: /bin/ls
第一个ALL是表示 目录 (ALL)权限 最后一列表示命令可以用ALL(表示所有命令)代替 让xpf用户拥有root的权限ls和cd权限
1[xpf@localhost /]$ cd /root 2-bash: cd: /root: 权限不够 3[xpf@localhost /]$ sudo cd /root 4[xpf@localhost /]$ sudo ls /root 5anaconda-ks.cfg
而xiang1 ALL=(ALL) NOPASSWD: /bin/ls 这里表示不用输入密码就能直接执行成功 参考文档https://www.cnblogs.com/chjbbs/p/6365922.html
3.9限制root远程登陆
1User_Alias FEI = xpf 2FEI ALL=(ALL) NOPASSWD: /usr/bin/su 3 4[root@localhost ~]# sudo su - 5上一次登录:六 4月 7 03:01:54 CST 2018pts/1 上 6控制不让远程登陆 7[root@localhost ~]# vi /etc/ssh/sshd_config 8把#PermitRootLogin yes 改成 PermitRootLogin no然后重启服务 9systemctl restart sshd.service 10[xpf@localhost /]$ su - root 11密码: 12su: 鉴定故障