0

Is there a way to specify a different default directory for ssh identity files?

Normally, the default directory is ~/.ssh, but I would like to specify (in the .ssh/config file I assume) a different location.

I can do this with individual hosts in the .ssh/config file using the IdentifyFile config option:

Host foo foo.bar 
    HostName foo.bar
    IdentityFile ~/.ssh/my-ssh-keys/id_rsa
    User foouser

What I would like to do is, for example, have ~/.ssh/my-ssh-keys be the default directory. I can't seem to find an option for it listed in Listing of client configuration options. Is there a way to override the default directory location?

1
  • I've perused the entire man ssh_config and I've been unable to find anything relevant aside from Include which allows to include more configuration files. Aug 23, 2020 at 2:58

1 Answer 1

0

ssh does not have a default directory for identity files, so I'm not sure what you are asking.

You can specify a default identity file using

Host *
    IdentityFile ~/.ssh/my-ssh-keys/id_rsa

I did not test this but according to the docs you could also use

Host *
    IdentityFile ~/.ssh/my-ssh-keys/id_rsa
    IdentityFile ~/.ssh/my-ssh-keys/id_dsa
    IdentityFile ~/.ssh/my-ssh-keys/id_ecdsa
    # etc.

if that is what you are after.

4
  • I does have a default location. It checks two locations: /etc/ssh (depending on your system) and ~/.ssh this is per the OpenSSH documentation. This answer specifies a default key for all hosts, not a default location to search for a key.
    – Allan
    Aug 23, 2020 at 18:45
  • @Allan you asked for a "default directory for ssh identity files" - /etc/ssh does not store identity files. ssh only has a few hardcoded identity files it checks and you can override all with the second part of my answer. Maybe you can update your question with what you are trying to achieve?
    – laktak
    Aug 23, 2020 at 19:06
  • What I want to achieve is clearly articulated in the question. On my Mac and on my FreeBSD box, in /etc/ssh there, are identity files. Reading man ssh_config states that it will try, during authentication, each file in both the systemwide and user ssh directory. So, if you have multiple keys in ~/ssh it will go though each one and try it. I want to specify a different directory that it will look in.
    – Allan
    Aug 23, 2020 at 19:15
  • Identity files are per user, it wouldn't make sense to put them into /etc/ssh.
    – laktak
    Aug 24, 2020 at 21:12

You must log in to answer this question.

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