Connecting to EC2 using keypair (.pem file) via Fabric

Mickey Cheong picture Mickey Cheong · Feb 21, 2011 · Viewed 21.2k times · Source

Anyone has any Fabric recipe that shows how to connect to EC2 using the pem file?

I tried writing it with this manner: Python Fabric run command returns "binascii.Error: Incorrect padding"

But I'm faced with some encoding issue, when I execute the run() function.

Answer

gak picture gak · Feb 22, 2011

To use the pem file I generally add the pem to the ssh agent, then simply refer to the username and host:

ssh-add ~/.ssh/ec2key.pem
fab -H ubuntu@ec2-host deploy

or specify the env information (without the key) like the example you linked to:

env.user = 'ubuntu'
env.hosts = [
    'ec2-host'
]

and run as normal:

fab deploy