Every time I need to use git pull, I need to run ps aux | grep ssh, kill all ssh process, included ssh-agent, and then I type the commands eval `ssh-agent` and ssh-add ~/.ssh/my_key. The configuration is not being maintained. (I have two keys generated, the first one is working well and the second one have this problem).
1 Answers
I found that I need to tell the ssh-agent what is the key when handling connections like github.com or any other. if you have remote (git remote -v) like git@github.com:path/to/file.git, you should create a ssh config file in the path ~/.ssh/config with the following configuration
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/<github_private_key>
Where the github_private_key is your private private key that you want to bind with the github.com remote. the Host configuration is an alias for the configuration, i am using the alias equal to the HostName because of my already configured remote.
In general case, if you have a remote like user@host:path/to/file.git
and you are configuring the connection with github, the configuration should have this content
Host <host>
HostName github.com
User <user>
IdentityFile ~/.ssh/<github_private_key>
To have this configuration in a best way, you can create a new configuration on ~/.ssh/config file like this
Host my-alias
HostName github.com
User git
IdentityFile ~/.ssh/<github_private_key>
Now, instead using git clone git@github.com:path/to/file.git you can use git clone git@my-alias:path/to/file.git
If you have the git repository already cloned, you can change you remote to git@my-alias:path/to/file.git.