ssh_upload 538 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python2
  2. import sys
  3. import subprocess
  4. def usage():
  5. print 'Usage: ssh_upload <user@host>'
  6. def cat_key(host):
  7. key = '$HOME/.ssh/id_rsa.pub'
  8. remote_cmd = '"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"'
  9. cmd = 'cat %s | ssh %s -- %s' % (key, host, remote_cmd)
  10. subprocess.call(cmd, shell=True)
  11. def main(args):
  12. if len(args) < 2:
  13. usage()
  14. sys.exit(1)
  15. host = args[-1]
  16. if host == '-h' or host == '--help':
  17. usage()
  18. sys.exit
  19. cat_key(host)
  20. main(sys.argv)