pm-suspend 必须由 root 运行:
he@x22:~/hep/links$ /usr/sbin/pm-suspend
This utility may only be run by the root user.
我建了一个链接,pms:
he@x22:~/hep/links$ ls -l pms
lrwxrwxrwx 1 he he 20 dec 17 22:13 pms -> /usr/sbin/pm-suspend
和预期的一样:
he@x22:~/hep/links$ ./pms
This utility may only be run by the root user.
但如果我更改目录并将 ~/hep/links 添加到路径中,它对普通用户来说就可以工作:
he@x22:~$ pms
whoami root
为了查看有效用户是谁,我在 /usr/sbin/pm-suspend 的顶部插入了:
#!/bin/sh
echo whoami $(whoami)
.....
root@x22:/home/he/hep/scripts# type -a pms
pms är ett alias för ”sudo pm-suspend”
pms är /home/he/hep/scripts/pms
pms är /home/he/hep/links/pms
有人能解释一下这里发生了什么吗?
当您
./pms
从~/hep/links
目录执行时,您正在通过新的符号链接执行脚本。但是当您执行时
pms
- 无论您在哪个目录中,或者是否已添加~/hep/links
到您的PATH
,您都不会通过链接调用它,而是执行别名sudo pm-suspend
。由于您可能曾经
sudo
编辑过该脚本并且仍处于超时期限内,因此您的凭据将被缓存并pm-suspend
以 root 身份执行,而无需提示进行身份验证。