I am trying to execute a script I uploaded to an AWS instance. If I run the following command in my MacBook Terminal, it succeeds:
ssh -o StrictHostKeyChecking=no -i ~/.ec2/my.pem ec2-user@ec2-<address>.amazonaws.com "chmod u+x ./myScript.sh"
I ported the same command to a simple shell script on my local machine, where I pass in the information:
#!/bin/sh
# myLocalScript.sh
host=$1
pem=$2
fileName=$3
ssh -o StrictHostKeyChecking=no -i $pemkey ec2-user@$host "chmod u+x ./$fileName"
When I run it using this command:
sh myLocalScript.sh ec2-user@ec2-<address>.amazonaws.com ~/.ec2/my.pem myScript.sh
I get the following error:
Warning: Identity file ec2-user@ec2-<address>.amazonaws.com not accessible: No such file or directory.
ssh: Could not resolve hostname chmod u+x ./myScript.sh: nodename nor servname provided, or not known
What am I doing wrong?
You need
$pemnot$pemkey.Additionally, you should get into the habit of double-quoting variables, except in very special situations where you really want an empty variable to “disappear”.