How to run arbitrary sudo command for Fabric without entering a password?

With Fabric, according to this documentation , you can run an arbitrary shell command without a fabfile , like this:

 fab -H host1,host2 -- echo 'hello, world!' 

You can also run sudo commands in the same way, but you will be prompted for a sudo password for each node in the list.

Is there a way to avoid entering a sudo password for each host, as if the Fabric sudo() function were working?

+6
source share
3 answers

just add the following line to etc / sudoers where myusername must be the intended user who will run sudo. You must understand the security implications of the following. You can also limit the options below to limit the commands that the user can use without a password.

 myusername ALL=(ALL) NOPASSWD: ALL 
+2
source

You can set env.password so that the fabric env.password magic or ...

... you can also use passwords for several machines:

 from fabric import env env.hosts = [' user1@host1 :port1', ' user2@host2.port2 '] env.passwords = {' user1@host1 :port1': 'password1', ' user2@host2.port2 ': 'password2'} 

See this answer: fooobar.com/questions/113851 / ...

+1
source

You may also consider pam authentication using ssh key-file. A good primer would be this blog post . Thus, you will not need to compromise security. You can even copy the key file before sudo operations to your remote account, provided that you have a qualified account. :-)

0
source

All Articles