Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric: Local command usage

Tags:

python

fabric

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)
like image 880
mlzboy Avatar asked Oct 15 '10 11:10

mlzboy


2 Answers

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.

like image 122
Chopsticks Avatar answered Oct 02 '22 19:10

Chopsticks


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

like image 20
eumiro Avatar answered Oct 02 '22 19:10

eumiro