Created
December 28, 2016 05:37
-
-
Save AndrewWalker/5ca8d2eec5095bb696d95d58dd1212f7 to your computer and use it in GitHub Desktop.
Pure python replacement for ssh_copy_id
This file contains 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
import argparse | |
import sys | |
import os | |
def ssh_copy_id(host='localhost', ssh='ssh', keyfile='~/id_rsa.pub', sshopts=()): | |
opts = ' '.join('-o ' + opt for opt in sshopts ) | |
cmd = 'cat %(keyfile)s | %(ssh)s %(opts)s %(host)s \'umask 077; mkdir -p .ssh; cat >> .ssh/authorized_keys\'' | |
os.system(cmd % locals()) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser('ssh-copy-id') | |
parser.add_argument('-e', | |
'--executable', | |
default = 'ssh') | |
parser.add_argument('-o', | |
dest='sshopt', | |
action='append') | |
parser.add_argument('-i', | |
'--identity-file', | |
default = '~/.ssh/id_rsa.pub') | |
parser.add_argument('host') | |
args = parser.parse_args(sys.argv[1:]) | |
ssh_copy_id(host=args.host, keyfile=args.identity_file, ssh=args.executable, sshopts=args.sshopt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment