0

I'm trying to connect to AWS instance through terminal using SSH with the public IP address and I keep getting:

Warning: Identity file .cer not accessible: No such file or directory. ubuntu@XXXXXXXX.us-east-2.compute.amazonaws.com: Permission denied (publickey).

I'm running this script to remote in, hosts.txt contains the IP address

#!/bin/bash
while read HOST INSTANCE_KEY;
do
if ssh -i $INSTANCE_KEY.cer ubuntu@$HOST '
STATUS=`/opt/agent.sh status | awk 'NR==1{print $3 $4}'`
[ "$STATUS" = "isrunning" ]
'; then
echo "$HOST == FAIL"
else
echo "$HOST == PASS"
fi
done < hosts.txt

I'm need to SSH to public IP Address using the Authentication Key received from AWS

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    It looks to me like you haven't configured the SSH public key correctly in your AWS instance. – Barmar Aug 20 '21 at 16:35
  • Right. I made the mistake of testing using a wrapper script that doesn't propagate. – Barmar Aug 20 '21 at 16:39
  • Use `ssh -n` to prevent `ssh` from reading the rest of your `hosts.txt` file and stopping the loop. See https://stackoverflow.com/questions/13800225/while-loop-stops-reading-after-the-first-line-in-bash – Barmar Aug 20 '21 at 16:40
  • 1
    The warning message indicates that `INSTANCE_KEY` isn't set, or else it would be something like `Warning: Identity file foo.cer not accessible...` (if `INSTANCE_KEY` had the value `foo`). – chepner Aug 20 '21 at 16:41
  • You likely have a line in the file that contains only a host name, without an associated key file name. – chepner Aug 20 '21 at 16:42

0 Answers0