Skip to content

Instantly share code, notes, and snippets.

@mtvbrianking
Created August 9, 2021 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtvbrianking/a9a7cc3dc421fb48b6cf265e6193643f to your computer and use it in GitHub Desktop.
Save mtvbrianking/a9a7cc3dc421fb48b6cf265e6193643f to your computer and use it in GitHub Desktop.
SSH into remote servers
#!/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