I'm trying to test the ssh connection of a set of hosts using a corresponding set of test user accounts.
testuser1 test ssh connection to server1,
testuser2 test ssh connection to server2,
testuser3 test ssh connection to server3 ect.
Each test user is logging in using a private key:
ssh -i ~/keys/testuser1key testuser1@server1
However, I'm running into an issue when putting this information into a variable. Here is what I have for a script so far:
for host in $(cat hosts) do if ssh -i $host 'true' exit then echo "SSH connection for $host ok" else echo "SSH connection for $host failed" fi done $SHELL
host file looks like this:
~/keys/testuser1key testuser1@server1 ~/keys/testuser2key testuser2@server2 ~/keys/testuser3key testuser3@server3 ...
I am getting errors such as
could not resolve hostname true
I think the space in the
host file are what's breaking the script. I've used a similar script no issue when running my user account and no "-i" ssh flag. (
Any help or suggestions on a better way to do this is appreciated!