Created
August 27, 2015 11:38
-
-
Save olavmrk/dac2f92864e25d9914c0 to your computer and use it in GitHub Desktop.
SSH with key from environment variable
This file contains hidden or 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/env python | |
from __future__ import print_function | |
from __future__ import unicode_literals | |
import os | |
import tempfile | |
import subprocess | |
import sys | |
if not 'SSH_KEY' in os.environ: | |
cmd = [ | |
'ssh', | |
'-o', 'StrictHostKeyChecking=no', | |
] | |
cmd += sys.argv[1:] | |
retcode = subprocess.call(cmd) | |
sys.exit(retcode) | |
with tempfile.NamedTemporaryFile() as ssh_key_file: | |
ssh_key_file.write(os.environ['SSH_KEY']) | |
ssh_key_file.flush() | |
cmd = [ | |
'ssh', | |
'-o', 'StrictHostKeyChecking=no', | |
'-i', ssh_key_file.name, | |
] | |
cmd += sys.argv[1:] | |
retcode = subprocess.call(cmd) | |
sys.exit(retcode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment