Created
April 3, 2013 18:10
-
-
Save yshnb/5303689 to your computer and use it in GitHub Desktop.
fabfile to setup ssh-key in remote-server
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
#!/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