Using an SSH keyfile with Fabric

后端 未结 8 1464
Happy的楠姐
Happy的楠姐 2020-11-28 18:42

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

相关标签:
8条回答
  • 2020-11-28 19:35

    As stated above, Fabric will support .ssh/config file settings after a fashion, but using a pem file for ec2 seems to be problematic. IOW a properly setup .ssh/config file will work from the command line via 'ssh servername' and fail to work with 'fab sometask' when env.host=['servername'].

    This was overcome by specifying the env.key_filename='keyfile' in my fabfile.py and duplicating the IdentityFile entry already in my .ssh/config.

    This could be either Fabric or paramiko, which in my case was Fabric 1.5.3 and Paramiko 1.9.0.

    0 讨论(0)
  • 2020-11-28 19:38

    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.

    0 讨论(0)
提交回复
热议问题