Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. if [ "$1" == "" ]; then
  4. echo Enter the box name Eg: machinexyz.machinehost.com
  5. read stagename
  6. else
  7. stagename=$1
  8. fi
  9.  
  10. temp=`ls /usr/bin | grep ssh.exe| wc -l`;
  11. if [ $temp == 0 ]; then
  12. echo Please install ssh in cygwin
  13. echo While installing cygwin, enable Openssh* options under Net
  14. fi
  15.  
  16. temp=`ls /usr/bin | grep scp.exe| wc -l`;
  17. if [ $temp == 0 ]; then
  18. echo Please install scp in cygwin
  19. fi
  20.  
  21. # Cleanup just in case
  22. if [ -f ~/.ssh/passwordless_key ]; then
  23. rm ~/.ssh/passwordless_key
  24. fi
  25.  
  26. # Check if the key already exists
  27. # If so copy it to passwordless_key
  28. if [ -f ~/.ssh/id_dsa.pub ]; then
  29. cp ~/.ssh/id_dsa.pub ~/.ssh/passwordless_key
  30. elif [ -f ~/.ssh/id_rsa.pub ]; then
  31. cp ~/.ssh/id_rsa.pub ~/.ssh/passwordless_key
  32. elif [ -f ~/.ssh/identity.pub ]; then
  33. cp ~/.ssh/identity.pub ~/.ssh/passwordless_key
  34. fi
  35.  
  36. # If not, create it
  37. if [ ! -f ~/.ssh/passwordless_key ]; then
  38. echo Generating key
  39. ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ''
  40. cp ~/.ssh/id_dsa.pub ~/.ssh/passwordless_key
  41. fi
  42.  
  43. # Copy the public key to the stage
  44. #scp ~/.ssh/passwordless_key $stagename:~/.ssh/authorized_keys
  45. cat ~/.ssh/passwordless_key | ssh $stagename "mkdir -m 0700 -p .ssh && cat - >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys"
  46.  
  47. # Cleanup
  48. rm ~/.ssh/passwordless_key
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement