Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an SSH keyfile with Fabric

Tags:

python

fabric

How do you configure fabric to connect to remote hosts using SSH keyfiles (for example, Amazon EC2 instances)?

like image 884
Yuval Adam Avatar asked Mar 16 '11 15:03

Yuval Adam


1 Answers

Finding a simple fabfile with a working example of SSH keyfile usage isn't easy for some reason. I wrote a blog post about it (with a matching gist).

Basically, the usage goes something like this:

from fabric.api import *  env.hosts = ['host.name.com'] env.user = 'user' env.key_filename = '/path/to/keyfile.pem'  def local_uname():     local('uname -a')  def remote_uname():     run('uname -a') 

The important part is setting the env.key_filename environment variable, so that the Paramiko configuration can look for it when connecting.

like image 114
Yuval Adam Avatar answered Sep 28 '22 02:09

Yuval Adam