I am trying to prevent bash to ask for sudo permission to run the port command (OSX packet manager) adding it to visudo. I basically tried to follow this SO thread but I still get an error
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
The same selfupdate command runs smoothly if I sudo it.
My visudo has the following lines
# User privilege specification root ALL=(ALL) ALL %admin ALL=(ALL) ALL %admin ALL=(ALL) NOPASSWD: /opt/local/bin/port
and I also tried susbtituitng the last line with
<user_name> ALL=(ALL) NOPASSWD: /opt/local/bin/port
What am I missing? Also can someone explain the syntax of the last line of the visudo file.
Advertisement
Answer
You actually want to achieve two things:
1. Making it possible to run sudo port without the need to enter a password.
You already solved that by adding the following line to /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.