-1

I am trying to ssh into my amazon server. I have two ways of doing it, one works and one doesn't, and I'm not sure why the second one does not work.

First way:

ssh -i path-to-pem-file username@public-ip

This works.

Second way:

ssh -i "path-to-pem-file" username@public-ip

This results in "Warning: Identity file "path-to-pem-file" not accessible".

Both of the above commands are run from the terminal on Mac OSX. Why do the double quotes break the statement? thanks.

makansij
  • 9,303
  • 37
  • 105
  • 183

1 Answers1

2

If your using shell expansion or other special characters their special meanings will not be interpreted when quoted. They are considered literal values.

You can replicate this with the ~ or special character for $HOME

Doesnt work

ssh -i "~/mypemkey.pem" ec2-user@somehost

Works

ssh -i ~/mypemkey.pem ec2-user@somehost

Essentially the ssh application is trying to find a literal file path ~/ instead of /Users/someuser/ when expanded.

Want to see it in action under the hood.... test it!

Create a simple bash script

echo "echo \$1" > test.sh

Execute it

/bin/bash test.sh ~/Desktop
    outputs: /Users/phpisuber01/Desktop

/bin/bash test.sh "~/Desktop"
    outputs: ~/Desktop
phpisuber01
  • 7,585
  • 3
  • 22
  • 26