Question

I want execute a command which needs sudo in local machine. So as the documentation suggests, I used the local command, but its asking me to enter the password. How can I avoid this? Is there some place where I can save my local machine password?

local('sudo /etc/init.d/tomcat6 start',capture=True)
Was it helpful?

Solution

Check the visudo command, which will allow you to edit the /etc/sudoers file, in which you can define users, commands and password-requirements on a machine (e.g. user mlzboy does not need to enter password in order to execute /etc/init.d/tomcat6). Don't forget this can create a security problem.

Sudoers manual

OTHER TIPS

If you do not plan to share the fabfile you can use:

echo "password\n" | sudo -S /etc/init.d/tomcat6 start

according to the sudo man page:

The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.

If you want to use sudo but on the loopback ip:

from fabric.api import sudo,env
env.hosts =['127.0.0.1']
sudo('aptitude search fabric')

No need to edit sudoers, given you have an ssh server running locally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top