比方说,who命令很危险。你可以分两步启用拦截。第一个步骤是启用它,第二个步骤是配置它。在这种情况下,我的用户不被允许运行who:
Defaults interceptczanik ALL = (ALL) ALL, !/usr/bin/who
当我通过sudo启动一个 root shell 会话并尝试运行who时,会发生以下情况:
$ sudo -s# whoSorry, user czanik is not allowed to execute '/usr/bin/who' as root on czplaptop.bash: /usr/bin/who: Permission denied
你可以很容易地完全禁用运行 shell:
Defaults interceptCmnd_Alias SHELLS=/usr/bin/bash, /usr/bin/sh, /usr/bin/cshczanik ALL = (ALL) ALL, !SHELLS
这意味着你不能通过 sudo启动 shell 会话。不仅如此,你也不能从编辑器中执行外部命令。当我试图从vi中启动ls命令时,就会出现这种情况:
$ sudo vi /etc/issueSorry, user czanik is not allowed to execute '/bin/bash -c /bin/ls' as root on czplaptop.Cannot execute shell /bin/bashPress ENTER or type command to continue
接下来是什么?
我希望读了我的文章后,自己尝试一下这些新功能。你可以通过你的软件包管理器在许多 Linux 发行版和 UNIX 变种上安装最新的 sudo,或者使用Sudo 网站上的二进制安装程序。