我遇到了与 sudo 和 su 相关的问题。
我已经设定了预期结果,请在这里帮助我。
Adding groups, users using below commands on server
groupadd group1
groupadd group2
useradd user1 -g group1
useradd user2 -g group2
passwd user1
passwd user2
I have now 2 users ready on server
192.168.1.15 - server
[root@hdp23ambari ~]# visudo
user1 hdp23ambari = PASSWD: !/usr/sbin/visudo, /usr/bin/sudo, /bin/su
user2 hdp23ambari = PASSWD: !/bin/su - user2, !/usr/bin/sudo, !/usr/sbin/visudo
vim /etc/ssh/sshd_config
DenyUsers root user2
AllowUsers *@192.168.1.*
DenyGroups
AllowGroups
192.168.1.10 - client
[root@laptop Documents]# ssh [email protected]
[email protected]'s password:
Last login: Thu Sep 24 00:06:33 2015 from laptop.narayana.local
[user1@hdp23ambari ~]$ sudo su - user2 [iam able to do it - this is expected]
[sudo] password for user1:
[user2@hdp23ambari ~]$ exit
logout
[user1@hdp23ambari ~]$ su - user2 [how do we prevent 'su - ' access from visudo ? - this is unexpected results coming up]
Password:
[user2@hdp23ambari ~]$
[root@laptop Documents]# ssh [email protected] [iam able to do it - this is expected]
[email protected]'s password:
Permission denied, please try again.
答案1
您对 su 和 sudo 有很大的混淆。[- sudo:https://en.wikipedia.org/wiki/Sudo] [- 苏:https://en.wikipedia.org/wiki/Su_(Unix)]
简而言之,通过执行 sudo,您所做的就是使用自己的密码切换到另一个用户,并且成功了(仅当您在 sudoers 中正确设置了配置时)。不同的是,执行“su -”实际上是切换到该用户,在这种情况下,您需要该用户的密码,而不是您自己的密码。
尝试为该用户设置密码并测试。