1

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).

  • "The configuration is not being maintained" – What do you mean? Not maintained across reboot? or from shell to shell? or within the same agent? See the beginning of [this answer](https://superuser.com/a/1735329/432690). `ssh` seeks for a key in few default locations, an agent is not required for this; so if one of your keys is exactly there then it will work without access to any agent. What are the exact paths to the keys? Do not respond in comments, [edit] the question and add information there. – Kamil Maciorowski Oct 19 '22 at 05:04
  • It is not maintained across reboot! – Alvaro Ernani Oct 24 '22 at 22:52

1 Answers1

2

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.