[ssh] Setting the default ssh key location

ssh will look for its keys by default in the ~/.ssh folder. I want to force it to always look in another location.

The workaround I'm using is to add the keys from the non-standard location to the agent:

ssh-agent
ssh-add /path/to/where/keys/really/are/id_rsa 

(on Linux and MingW32 shell on Windows)

This question is related to ssh

The answer is


If you are only looking to point to a different location for you identity file, the you can modify your ~/.ssh/config file with the following entry:

IdentityFile ~/.foo/identity

man ssh_config to find other config options.


man ssh gives me this options would could be useful.

-i identity_file Selects a file from which the identity (private key) for RSA or DSA authentication is read. The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro- tocol version 2. Identity files may also be specified on a per- host basis in the configuration file. It is possible to have multiple -i options (and multiple identities specified in config- uration files).

So you could create an alias in your bash config with something like

alias ssh="ssh -i /path/to/private_key"

I haven't looked into a ssh configuration file, but like the -i option this too could be aliased

-F configfile Specifies an alternative per-user configuration file. If a configuration file is given on the command line, the system-wide configuration file (/etc/ssh/ssh_config) will be ignored. The default for the per-user configuration file is ~/.ssh/config.


Questions with ssh tag:

Starting ssh-agent on Windows 10 fails: "unable to start ssh-agent service, error :1058" How to solve "sign_and_send_pubkey: signing failed: agent refused operation"? key_load_public: invalid format ssh connection refused on Raspberry Pi Getting permission denied (public key) on gitlab Verify host key with pysftp Can't connect to Postgresql on port 5432 Checkout Jenkins Pipeline Git SCM with credentials? How to open remote files in sublime text 3 how to setup ssh keys for jenkins to publish via ssh How to pass a user / password in ansible command ssh : Permission denied (publickey,gssapi-with-mic) Composer update memory limit Forward X11 failed: Network error: Connection refused Unable to negotiate with XX.XXX.XX.XX: no matching host key type found. Their offer: ssh-dss Connect over ssh using a .pem file How to ignore ansible SSH authenticity checking? How to install sshpass on mac? Copying files from server to local computer using SSH SSH Key: “Permissions 0644 for 'id_rsa.pub' are too open.” on mac Is there a default password to connect to vagrant when using `homestead ssh` for the first time? Best way to script remote SSH commands in Batch (Windows) Changing an AIX password via script? How to fix request failed on channel 0 Github permission denied: ssh add agent has no identities .ssh/config file for windows (git) vagrant login as root by default How can I remove an SSH key? Keep SSH session alive AWS - Disconnected : No supported authentication methods available (server sent :publickey) Git Bash: Could not open a connection to your authentication agent Download files from SFTP with SSH.NET library Vagrant ssh authentication failure Vagrant stuck connection timeout retrying ssh-copy-id no identities found error How to download a file from my server using SSH (using PuTTY on Windows) Using putty to scp from windows to Linux Jenkins: Failed to connect to repository SSH Key - Still asking for password and passphrase Disable password authentication for SSH Putty: Getting Server refused our key Error Is there a way to continue broken scp (secure copy) command process in Linux? ssh remote host identification has changed How do I force detach Screen from another SSH session? scp copy directory to another server with private key auth Run local python script on remote server Google server putty connect 'Disconnected: No supported authentication methods available (server sent: publickey) Could not create work tree dir 'example.com'.: Permission denied ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known .bashrc: Permission denied