Skip to content

Instantly share code, notes, and snippets.

@yshnb
Created April 3, 2013 18:10
Show Gist options
  • Save yshnb/5303689 to your computer and use it in GitHub Desktop.
Save yshnb/5303689 to your computer and use it in GitHub Desktop.
fabfile to setup ssh-key in remote-server
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys,time
import fabric
from fabric.contrib.files import *
from fabric.api import *
from fabric.operations import *
import ilogue.fexpect
env.use_ssh_config = True
# setup ssh-key to remote-server
def ssh_config(keyfile):
pubkey = '~/'+keyfile+'.pub'
put(pubkey, pubkey)
if (not exists('.ssh')):
run('mkdir .ssh')
run('chmod 700 ~/.ssh')
if (not exists('~/.ssh/authorized_keys')):
run('touch ~/.ssh/authorized_keys')
run('''
cat {pubkey} >> {auth_keys}
chmod 600 {auth_keys}
rm {pubkey}
'''.format(pubkey=pubkey,auth_keys='~/.ssh/authorized_keys'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment