Advertisement
Guest User

Untitled

a guest
Mar 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. echo "Enter the user you want to connect with (sudo needs to be enabled and installed)"
  2. read -e rUser
  3.  
  4. echo "Enter the host you want to connect to"
  5. read -e rHost
  6.  
  7.  
  8. echo "Enter the SSH-port"
  9. read -e rPort
  10.  
  11. read -s -p "Enter Password: " password
  12.  
  13. if [ ! -d "$HOME/.ssh" ] && [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
  14. echo -e "Private / Public keys not generated"
  15. echo -e "Generating..."
  16. ssh-keygen -b 4096
  17. fi
  18.  
  19. cat "$HOME/.ssh/id_rsa.pub" | ssh "$rUser@$rHost" -p $rPort "cat >> ~/.ssh/authorized_keys"
  20.  
  21. remoteUsers=($(ssh "$rUser@$rHost" -p $remotePort
  22. 'echo '"$password"' | sudo -S ls /home/ && for localUser
  23. in $(ls /home | grep -v $USER); do sudo mkdir -p /home/$localUser/.ssh &&
  24. sudo touch /home/$localUser/.ssh/authorized_keys
  25. && sudo chown "$localUser:$localUser" /home/$localUser/.ssh/authorized_keys &&
  26. cat /home/$USER/.ssh/authorized_keys | sudo tee
  27. --append /home/$localUser/.ssh/authorized_keys > /dev/null; done'))
  28.  
  29. for remoteUser in "${remoteUsers[@]}"
  30. do
  31. cat <<< "Host ${remoteUser}_${rHost}
  32. HostName $rHost
  33. Port $rPort
  34. User $remoteUser" >> /home/$USER/.ssh/config
  35. done
  36.  
  37. #!/bin/bash
  38.  
  39. echo "Enter the user you want to connect with (sudo needs to be enabled and installed)"
  40. read -e rUser # -e Identifier bash feature
  41.  
  42. echo "Enter the host you want to connect to"
  43. read -e rHost # -e Identifier bash feature
  44.  
  45.  
  46. echo "Enter the SSH-port"
  47. read -e rPort
  48.  
  49. read -s -p "Enter Password: " password
  50.  
  51. # Generate private public ssh-keys
  52. if [ ! -d "$HOME/.ssh" ] && [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
  53. echo -e "Private / Public keys not generated"
  54. echo -e "Generating..."
  55. ssh-keygen -b 4096
  56. fi
  57.  
  58. # Send public key to remote host
  59. echo "Sending public key to remote host..."
  60. cat "$HOME/.ssh/id_rsa.pub" | ssh "$rUser@$rHost" -p $rPort "cat >> ~/.ssh/authorized_keys"
  61. remoteUsers=($(ssh "$rUser@$rHost" -p $rPort 'echo '"$password"' | sudo -S ls /home/ && for localUser in $(ls /home | grep -v $USER); do sudo mkdir -p /home/$localUser/.ssh && sudo touch /home/$localUser/.ssh/authorized_keys && sudo chown "$localUser:$localUser" /home/$localUser/.ssh/authorized_keys && cat /home/$USER/.ssh/authorized_keys | sudo tee --append /home/$localUser/.ssh/authorized_keys > /dev/null; done'))
  62.  
  63. for remoteUser in "${remoteUsers[@]}"
  64. do
  65. cat <<< "Host ${remoteUser}_${rHost}
  66. HostName $rHost
  67. Port $rPort
  68. User $remoteUser" >> /home/$USER/.ssh/config
  69. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement