Guy
Guy

Reputation: 13286

Permanently add an SSH key

To get access to my remote git I add a reference to the SSH every time I push or pull:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_bit_rsa" git pull origin master

Is there a way to have the git remember the SSH so I don't need to add it each time?

Upvotes: 3

Views: 15946

Answers (2)

axiac
axiac

Reputation: 72177

Git doesn't care about your SSH keys. Behind the scene it invokes ssh. If the environment variable GIT_SSH_COMMAND is set then it doesn't use ssh but the content of the GIT_SSH_COMMAND variable.

One option to make it permanent is to write:

export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_bit_rsa"

in your .profile (or .bash_profile) but it produces more harm than good if you use more than one remote hosts.

The correct way to solve it is to properly configure ssh. Edit the file ~/.ssh/config (or create it if it doesn't exist) and put into it:

Host bitbucket.com
User guy
IdentityFile = ~/.ssh/id_bit_rsa

Of course, replace bitbucket.com with the actual name of the server that hosts your Git repo (I guessed BitBucket from the "bit" part of your key file) and guy with your name on the host.

Upvotes: 9

haboutnnah
haboutnnah

Reputation: 1186

You could do this:

Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_github

(replacing the user and hostname as needed, as well as the identity file)

in ~/.ssh/config

Upvotes: 6

Related Questions