I'm getting this error when running ssh myhost2:

no such identity: /home/myusername/.ssh/myhost2_rsa: No such file or directory

The details

On Ubuntu 16.04.4 LTS, I recently configured my SSH client to connect to multiple servers using different private keys.

My ~/.ssh/config file has multiple host declarations, each with a different IdentityFile as below:

Host myhost1
        HostName myhost1.com
        user myhost1user
        IdentityFile ~/.ssh/myhost1_rsa

Host myhost2
        HostName myhost2.com
        user myhost2user
        IdentityFile ~/.ssh/myhost2_rsa

Host myhost3
        HostName myhost3.com

Host myhost4
        HostName xxx.xxx.xxx.xx
        user myhost4user
        IdentityFile ~/.ssh/myhost4_rsa

When I set these up a few days ago, all were working properly. In other words, I could use a command like this:

ssh myhost2

...and the SSH connection would work as expected.

Today, using the same command results in this error:

no such identity: /home/myusername/.ssh/myhost2_rsa: No such file or directory

Convinced that this was a file permissions problem, I have checked and rechecked that there are no group permissions on my home folder nor on my .ssh folder.

  • My ~/.ssh folder has 700 permissions
  • My /home/myusername folder has 700 permissions

And I've checked and rechecked the private key files:

  • Each of my private key files (e.g. myhost2_rsa) has 600 permissions
  • Each of my private key files is owned by my user account (thanks for asking about this, @steeldriver). Here's the output of namei -l /home/myusername/.ssh/myhost2_rsa:

f: /home/myusername/.ssh/myhost2_rsa drwxr-xr-x root root / drwxr-xr-x root root home drwx------ myusername myusername myusername drwx------ myusername myusername .ssh -rw------- myusername myusername myhost2_rsa

Since these were working a few days ago, I'm stupefied. This is still a recent Ubuntu setup for me, so I've been adding software and making configuration tweaks, but I can't think of anything that would have affected SSH or my home folder permissions.

Furthermore, I can still SSH into these same hosts from my Win7 machine via Putty using the same private keys.

Any ideas about what else I should be checking?

  • Did you verify the files' ownership as well as their permissions? what is the output of namei -l /home/myusername/.ssh/myhost2_rsa Mar 28, 2018 at 17:46
  • Thanks @steeldriver. I did verify ownership, which I think is correct. Here's the output of namei -l /home/myusername/.ssh/myhost2_rsa Mar 28, 2018 at 18:10
  • Sorry @steeldriver - My comment markdown chops here are sorely lacking. Here it is: pastebin.com/BkNccJeH Mar 28, 2018 at 18:16

1 Answer 1


Permissions on ~/.ssh/config must also be set to 600.

Once I set these permissions with chmod 600 ~/.ssh/config, the usual behavior began to work again (e.g. running command ssh myhost4 resulted in a successful SSH connection to the server without an error).

  • It might be that ssh -vvv myhost4 would have told about the wrong permissions, but I'm not sure. You can revert the permissions and try.
    – PerlDuck
    Mar 29, 2018 at 9:37
  • I scoured that output, @PerlDuck. Didn't see it in there. But reverting the permissions and trying again might be worthwhile. I'll let you know what I find. Mar 31, 2018 at 12:55
  • Interesting. When I do chmod 666 ~/.ssh/config then a simple ssh myhost fails with Bad owner or permissions on /home/pduck/.ssh/config. After chmod 660 or chmod 600 it works. ssh -V returns OpenSSH_7.5p1 Ubuntu-10ubuntu0.1, OpenSSL 1.0.2g 1 Mar 2016. Perhaps that makes a difference. I'm on 17.10.
    – PerlDuck
    Mar 31, 2018 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .