Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo "Enter the user you want to connect with (sudo needs to be enabled and installed)"
- read -e rUser
- echo "Enter the host you want to connect to"
- read -e rHost
- echo "Enter the SSH-port"
- read -e rPort
- read -s -p "Enter Password: " password
- if [ ! -d "$HOME/.ssh" ] && [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
- echo -e "Private / Public keys not generated"
- echo -e "Generating..."
- ssh-keygen -b 4096
- fi
- cat "$HOME/.ssh/id_rsa.pub" | ssh "$rUser@$rHost" -p $rPort "cat >> ~/.ssh/authorized_keys"
- remoteUsers=($(ssh "$rUser@$rHost" -p $remotePort
- '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'))
- for remoteUser in "${remoteUsers[@]}"
- do
- cat <<< "Host ${remoteUser}_${rHost}
- HostName $rHost
- Port $rPort
- User $remoteUser" >> /home/$USER/.ssh/config
- done
- #!/bin/bash
- echo "Enter the user you want to connect with (sudo needs to be enabled and installed)"
- read -e rUser # -e Identifier bash feature
- echo "Enter the host you want to connect to"
- read -e rHost # -e Identifier bash feature
- echo "Enter the SSH-port"
- read -e rPort
- read -s -p "Enter Password: " password
- # Generate private public ssh-keys
- if [ ! -d "$HOME/.ssh" ] && [ ! -f "$HOME/.ssh/id_rsa" ] && [ ! -f "$HOME/.ssh/id_rsa.pub" ]; then
- echo -e "Private / Public keys not generated"
- echo -e "Generating..."
- ssh-keygen -b 4096
- fi
- # Send public key to remote host
- echo "Sending public key to remote host..."
- cat "$HOME/.ssh/id_rsa.pub" | ssh "$rUser@$rHost" -p $rPort "cat >> ~/.ssh/authorized_keys"
- 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'))
- for remoteUser in "${remoteUsers[@]}"
- do
- cat <<< "Host ${remoteUser}_${rHost}
- HostName $rHost
- Port $rPort
- User $remoteUser" >> /home/$USER/.ssh/config
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement