The fabric continues to request a password using an SSH connection.

I try to connect to the azure windows window using fabric, but despite the fact that I configure the ssh connection to execute commands, the fabric continues to request a password.

This is my fabric file:

def azure1(): env.hosts = ['host.cloudapp.net:60770'] env.user = 'adminuser' env.key_filename = './azure.key' def what_is_my_name(): run('whoami') 

I run it as:

 fab -f fabfile.py azure1 what_is_my_name 

or

 fab -k -f fabfile.py -i azure.key -H adminuser@host.cloudapp.net:60770 -p password what_is_my_name 

But nothing happened, he continues to request the user password, despite the fact that I enter it correctly.

 Executing task 'what_is_my_name' run: whoami Login password for 'adminuser': Login password for 'adminuser': Login password for 'adminuser': Login password for 'adminuser': 

If I try to connect directly to ssh, it works fine.

 ssh -i azure.key -p 60770 adminuser@host.cloudapp.net 

I tried the recommendations given in other questions ( q1 q2 q3 ), but nothing works.

Any idea what I'm doing wrong?

thanks

+8
fabric openssl azure openssh paramiko
source share
2 answers

Finally, I found that the problem is with generating a pair of public and private keys.

I followed the steps described in the windows azure guide , where the keys are generated using openssl, so the result of the process opens the public key stored in the pem file, which you must load into your instance during the creation process.

The problem is that the received private key is not recognized correctly by paramiko, so the fabric will not work. If you try to open an ssh connection using paramiko from the python interpreter:

 >>> import paramiko, os >>> paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) >>> ssh = paramiko.SSHClient() >>> ssh.load_host_keys('private_key_file.key') # private key file generated using openssl >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) >>> ssh.connect("web1.cloudapp.net",port=56317) 

Gives me an error:

 DEBUG:paramiko.transport:Trying SSH agent key a9d8dd41609191ebeedbe8df768ad8c9 DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (publickey) failed. Traceback (most recent call last): File "<stdin>", line 1, in <module> File ".. /paramiko/client.py", line 337, in connect self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys) File ".. /paramiko/client.py", line 528, in _auth raise saved_exception paramiko.PasswordRequiredException: Private key file is encrypted 

If the key file is not encrypted.

To solve this problem, I created a key pair using openssh and then convert the public key to pem to load it into azure:

 # Create key with openssh ssh-keygen -t rsa -b 2048 -f private_key_file.key # extract public key and store as x.509 pem format openssl req -x509 -days 365 -new -key private_key_file.key -out public_key_file.pem # upload public_key_file.pem file during instance creation # check connection to instance ssh -i private_key_file.key -p 63534 adminweb@host.cloudapp.net 

This solved the problem.

+6
source share

To debug network ssh connections, add these lines to your file:

 import paramiko, os paramiko.common.logging.basicConfig(level=paramiko.common.DEBUG) 

This will print all paramiko debugging messages. Paramiko is the ssh library that the fabric uses.

Note that with Fabric 1.4 you need to specifically enable the use of ssh config:

 env.use_ssh_config = True 

(Note: I am sure that I am absolutely sure that my fabfile worked with Fabric> 1.5 without this option, but now I am not upgrading to 1.10).

+4
source share

All Articles