Skip to content

Instantly share code, notes, and snippets.

@kkleidal
Created March 15, 2017 20:16
Show Gist options
  • Save kkleidal/2b37740e2b33bea770f48211dc75eed0 to your computer and use it in GitHub Desktop.
Save kkleidal/2b37740e2b33bea770f48211dc75eed0 to your computer and use it in GitHub Desktop.
import subprocess
import base64
def keyscan(host):
p = subprocess.Popen(['/bin/sh', '-c', '(ssh-keyscan %s | grep ssh-rsa) 2>/dev/null' % host], stdout=subprocess.PIPE)
config = p.stdout.read().decode('ascii').split(' ')
p.wait()
if p.returncode != 0:
raise Exception("Could not scan %s for SSH key." % host)
config[2] = paramiko.RSAKey(data=base64.b64decode(config[2]))
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment