Skip to content

Instantly share code, notes, and snippets.

@cagerton
Last active August 29, 2015 13:57
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 cagerton/9441105 to your computer and use it in GitHub Desktop.
Save cagerton/9441105 to your computer and use it in GitHub Desktop.
Simple script to fetch an ssh host key.
#!/usr/bin/env python2.7
"""Usage: fetch_hostkey.py <host> [<port>]"""
import paramiko, docopt
opt = docopt.docopt(__doc__)
host = opt['<host>']
port = int(opt['<port>'] or 22)
t = paramiko.Transport((host, port))
t.connect()
k = t.get_remote_server_key()
t.close()
kh_line = "%s %s %s" % (host, k.get_name(), k.get_base64())
print(kh_line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment