macossshdirectoryenvironment-variableshome-directory

Change the location of the .ssh directory on macOS


When generating ssh keys, a folder called .ssh is generated in my home directory.

Is there any way to move this folder to another location, such as .secure/ssh?
As an example, I can change the location of zsh history files by modifying the environmental variable $HISTFILE.

In terms of ssh, the only information I can find is that the directory is hard-coded to $HOME in which case there is nothing I can do. Is this indeed the case? If not, what is the proper environmental variable / method for macOS?


Solution

  • The default location of various items is ~/.ssh. There is no option to change that directory, though various options exist for individual assets found in this directory. For example, -F selects a configuration file other than ~/.ssh/config, -i selects a different identity file other than ~/.ssh/id_rsa et al., etc.