Created
September 28, 2013 01:06
-
-
Save eddieantonio/6737282 to your computer and use it in GitHub Desktop.
Fabric: task to authorize your SSH key on a remote host.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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