Jakim
Jakim

Reputation: 1813

How to change ssh default config name or location?

By default the ssh config file is ~/.ssh/config, but for some historical reason, there already have a directory ~/.ssh/config/, so I want to change the ssh config file name or location, so my ssh can pick the new config file up.

I already tried ssh -F /path/to/configfile, but this will require me to run ssh command each time, I am expecting a persistent configuration, so that it can be affected by other ssh related commands as well, such as git.

Upvotes: 6

Views: 12381

Answers (2)

Vinz
Vinz

Reputation: 1

More simple :

Make a sim link of your config file in another directory.

First step : create a file (root mode) in /etc/ssh/my_git_project/config

Second step (user mode) :

ln -s /etc/ssh/my_git_project/myhosts_config ~/.ssh/config

Upvotes: 0

LeGEC
LeGEC

Reputation: 51800

Copying this answer found on SuperUser :

Environment variable GIT_SSH_COMMAND:

From Git version 2.3.0, you can use the environment variable GIT_SSH_COMMAND like this:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example" git clone example

Note that -i can sometimes be overridden by your config file, in which case, you should give SSH an empty config file, like this:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone example

Configuration core.sshCommand:

From Git version 2.10.0, you can configure this per repo or globally, so you don't have to set the environment variable any more!

git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"
git pull
git push

Upvotes: 7

Related Questions