Skip to content

Instantly share code, notes, and snippets.

@brianpartridge
Created December 20, 2012 04:47
Show Gist options
  • Save brianpartridge/4343021 to your computer and use it in GitHub Desktop.
Save brianpartridge/4343021 to your computer and use it in GitHub Desktop.
Remote SSH To Anubis
import json
from dropbox import client, rest, session
import webbrowser
import keychain
import sys
import os
### Config
config = json.load(open('config.json', 'r'))
USER = 'brian'
SERVICE = 'dropbox'
APP_KEY = config['dropbox-app-key']
APP_SECRET = config['dropbox-app-secret']
ACCESS_TYPE = 'dropbox'
### Functions
def getClient():
sess = session.DropboxSession(APP_KEY, APP_SECRET, ACCESS_TYPE)
key = keychain.get_password(SERVICE, 'key')
secret = keychain.get_password(SERVICE, 'secret')
sess.set_token(key, secret)
return client.DropboxClient(sess)
def sshToHost(user, host):
print "Connecting to %s" % host
url = 'ssh://%s@%s' % (user, host)
webbrowser.open(url)
### Logic
path, script = os.path.split(sys.argv[0])
name, ext = os.path.splitext(script)
print "### %s ### " % name
client = getClient()
print "Dropbox account:", client.account_info()['email']
# Retrieve anubis's public IP from Dropbox and then SSH to it
f = client.get_file('/anubis_IP.txt')
lines = f.read().splitlines()
for l in lines:
if l.startswith('Public'):
components = l.split('\t')
host = components[-1]
sshToHost(USER, host)
print "### Done ###"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment