Skip to content

Instantly share code, notes, and snippets.

@Ceasar
Created February 20, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ceasar/9122195 to your computer and use it in GitHub Desktop.
Save Ceasar/9122195 to your computer and use it in GitHub Desktop.
"""
fab -H [hostname] [command]
"""
from fabric.api import run
HOME = '/Users/ceasarbautista'
def authorize():
"""Authorize access to a remote machine.
Password checks will no longer be required.
Usage: fab -H [hostname] authorize
"""
with open('%s/.ssh/id_rsa.pub' % HOME) as f:
public_key = f.read()
run('echo "%s" >> .ssh/authorized_keys' % (public_key,))
def alias(alias, user, hostname, port=22):
"""Set an alias for remote machine.
Usage: fab alias:alias,user,hostname,port
"""
with open('%s/.ssh/config' % HOME, 'a') as f:
f.write('Host %s' % alias)
f.write('\n HostName %s' % hostname)
f.write('\n Port %s' % port)
f.write('\n User %s' % user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment