-3

我试图阻止 bash 请求sudo运行port command(OSX 数据包管理器)将其添加到visudo. 我基本上试图遵循这个SO 线程,但我仍然得到一个错误

manfredo@cave05:~$ port selfupdate
--->  Updating MacPorts base sources using rsync
Error: Error synchronizing MacPorts sources: command execution failed
Please run `port -v selfupdate' for details.
Error: /opt/local/bin/port: port selfupdate failed: Error synchronizing MacPorts sources: command execution failed

如果我这样做,相同的selfupdate命令运行顺利sudo

visudo的有以下几行

# User privilege specification
  root     ALL=(ALL) ALL
  %admin   ALL=(ALL) ALL
  %admin ALL=(ALL) NOPASSWD: /opt/local/bin/port

而且我还尝试将最后一行替换为

<user_name> ALL=(ALL) NOPASSWD: /opt/local/bin/port

我错过了什么?也有人可以解释visudo文件最后一行的语法。

4

1 回答 1

1

您实际上想要实现两件事:

1.sudo port无需输入密码即可运行。

您已经通过将以下行添加到/etc/sudoers

%admin ALL=(ALL) NOPASSWD: /opt/local/bin/port

2. Making it possible to run sudo port without the need to explicitely type sudo

This can be done by an shell alias. Since the question is tagged bash I assume your shell is bash. In that case modify your .bashrc and add the following line:

alias port='sudo port'

Start a new shell and it should work.

于 2016-10-24T15:03:40.670 回答