Skip to content

Instantly share code, notes, and snippets.

@eddieantonio
Created September 28, 2013 01:06
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save eddieantonio/6737282 to your computer and use it in GitHub Desktop.
Save eddieantonio/6737282 to your computer and use it in GitHub Desktop.
Fabric: task to authorize your SSH key on a remote host.
"""
Installs your SSH key on other hosts. A fabfile for lazy people.
"""
from fabric.api import task, run, put, env, cd
# Use sh instead of bash.
env.shell = '/bin/sh -l -c'
@task
def add_ssh_key(identity='~/.ssh/id_rsa.pub'):
# Copy the key over.
REMOTE_PATH = '~/id.pub'
put(identity, REMOTE_PATH)
with cd('~'):
# Make sure the SSH directory is created.
run('mkdir -p .ssh')
# And append to the authrized keys.
run('cat %(REMOTE_PATH)s >> ~/.ssh/authorized_keys' % locals())
# Be thourough and leave no trace of this interaction!
run('rm %(REMOTE_PATH)s' % locals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment