Skip to content

Instantly share code, notes, and snippets.

@mastergenius
Created November 21, 2012 07:29
Show Gist options
  • Save mastergenius/4123591 to your computer and use it in GitHub Desktop.
Save mastergenius/4123591 to your computer and use it in GitHub Desktop.
Append ssh public key to remote servers with fabric
from fabric.api import local, run, env, cd
from fabric.contrib import files
import os
#env.hosts = []
PUB_KEY = "~/.ssh/id_rsa.pub"
def install_public_key(pubkey_file=PUB_KEY):
with open(os.path.expanduser(pubkey_file)) as fd:
ssh_key = fd.readline().strip()
with cd('~/'):
run('mkdir -p .ssh')
run('chmod 700 ~/.ssh')
files.append('.ssh/authorized_keys', ssh_key)
run('chmod 644 .ssh/authorized_keys')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment