Created
August 9, 2021 20:23
-
-
Save mtvbrianking/a9a7cc3dc421fb48b6cf265e6193643f to your computer and use it in GitHub Desktop.
SSH into remote servers
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
#!/bin/bash | |
# https://stackoverflow.com/q/13928116/2732184 | |
# https://stackoverflow.com/q/1405324/2732184 | |
SERVERS=("LOCAL", "REMOTE") | |
HOSTS=("127.0.0.1", "165.56.23.4") | |
PORTS=("22", "3409") | |
USERS=("root", "jdoe") | |
KEYS=("secret", "Ytrewq!123") | |
SCRIPT="echo $(whoami)@$(hostname):$(pwd); exit" | |
for i in ${!HOSTS[*]} ; do | |
# echo "sshpass -p '${KEYS[i]}' ssh ${USERS[i]}@${HOSTS[i]} -p ${PORTS[i]}" | |
echo "${SERVERS[i]} >>> ssh ${USERS[i]}@${HOSTS[i]} -p ${PORTS[i]}" | |
sshpass -p "${KEYS[i]}" \ | |
ssh \ | |
${HOSTS[i]} \ | |
-p ${PORTS[i]} \ | |
-l ${USERS[i]} \ | |
-o StrictHostKeyChecking=no \ | |
-o ConnectTimeout=5 \ | |
-o LogLevel=error \ | |
-o BatchMode=no \ | |
exit | |
echo -e "..." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment