Take the 2-minute tour ×

I'm able to ssh -i mykey.pem to EC2. I'm able to scp -i mykey.pem to EC2. But when I try to rsync -avz -e "ssh -i mykey.pem" I get this error:

Warning: Identity file mykey.pem not accessible: No such file or directory.
Permission denied (publickey).
rsync error: unexplained error (code 255) at io.c(605) [sender=3.0.9]

Any suggestions what I've done wrong?

share|improve this question
Have you considered setting up an SSH agent, or adding the key to your .ssh/config file so you don't need to provide an option at all? –  Zoredache Sep 24 '12 at 21:46
@Zoredache I don't know how to do that but it sounds like a good idea. –  isomorphismes Sep 24 '12 at 21:49
Identity file - serverfault.com/a/418755/984 –  Zoredache Sep 24 '12 at 22:12
what's the permissions on the pem file ? (la -l) –  Sirex Sep 24 '12 at 22:22
@Sirex I changed them to chmod 400 mykey.pem based on some advice elsewhere on the Web. (or maybe it was based on an error message) –  isomorphismes Sep 26 '12 at 3:13

2 Answers 2

Make sure the .pem file is indeed where you think.

Try rsync -avz -e "ssh -i ./mykey.pem" using a ./.

Note: For that example, your .pem must be inside the current working directory. If it's elsewhere, then change it to use an absolute path (/home/me/path/to/file.pem)

share|improve this answer
Hey, good suggestion but that's not the problem. –  isomorphismes Sep 24 '12 at 21:49
+1 for ionFish. I just verified this exact issue with my own AWS setup. Relative path to the private key fails with the above error, full absolute path works. I'm guessing it's a subshell issue, but use the full path and you should be fine. –  khoxsey Sep 26 '12 at 4:39
@khoxsey I'm using the full path already. I have it working with ssh -i /full/path/to/mykey.pem and scp -i /full/path/to/mykey.pem so the full path must be correct. –  isomorphismes Sep 26 '12 at 6:59
Using it already? That's my bad then. Unfortunately, that puts this into the realm of "it works on my machine", which is annoyingly unhelpful. –  khoxsey Sep 26 '12 at 16:31
Or just add the key/site to your ~/.ssh/config directory and be done with it. –  gravyface Sep 26 '12 at 17:14

As a debugging angle, try running ssh-agent in your shell session as described in this SO answer on a similar question. Basically, you run ssh-agent locally, add your key, and then see if rsync picks it up properly. The idea is to flush out some other error, hopefully providing some insight into the real problem (since we've come up dry in the comments).

Command string is this:

eval $(ssh-agent)
ssh-add path/to/mykey.pem
rsync -avz localfile remoteuser@ec2-instance:/remotelocation

This works in my environment for access to my AWS systems.

share|improve this answer

Your Answer


