Reputation: 3092
I searched around and I really couldn't get an answer on this but for some reason, fabric keeps asking for password but paramkio doesn't
import paramiko
mykey = paramiko.RSAKey.from_private_key_file('/path/to/key')
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('<ip>', username='me', pkey=mykey)
(stdin, stdout, stderr) = client.exec_command('ls /home') #works
for line in stdout.readlines():
print line
client.close()
But fabric doesn't
from fabric.api import sudo
env.user = 'me'
env.hosts = 'ip'
env.key_filename = '/path/to/key'
def run():
sudo('ls') #asks for password
Also, direct ssh
for that user works. So does scp
. So it can't be public key or ssh agent issues.
Anyone know what is going on with Fabric?
Upvotes: 0
Views: 352
Reputation: 71
The problem is in this line:
sudo('ls') #asks for password
Fabric asks you for password to execute command on remote host as sudo, so try to change sudo() to run().
If you still want to use sudo but without password, then I suggest searching for settung up passwordless sudo, but still only for specific commands only.
Upvotes: 1