I am copying the public key of the pem file generated from External Box to all EC2 instances. This prompts for password for first time Therafter I am able to do scp to all EC2 instance without password using PEM_PATH.

After 1st run I am trying to check if external box is able to SSH into without password using below code

return_code=$(ssh -i $PEM_PATH $SWARM_UNAME@$SWARM_NODE)

But this is not returning.

PEM_PATH is the path to my pem file

Please suggest


You can check ssh connection via command


But to capture return code you should use code like this:


and in variable ERR_CODE you will have exit code of script

  • @Zaks, do you get any errors, messages? And what is the content of variable ERR_CODE? Have you try to remove -q and check? – Romeo Ninov Dec 16 '18 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.