How can I add an already generated SSH key to git bash?
Solution 1
On windows you might need to start the ssh agent like this
# start the ssh-agent in the background
$ eval $(ssh-agent -s)
> Agent pid 59566
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
$ ssh-add <path/to/key>
Got this information from here under "Adding your SSH key to the ssh-agent": https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent
Solution 2
I don't think there is any specific config in gitbash itself. You have to put the key in the default location ~\.ssh/id_rsa
and it will be used. If you need to have it somewhere else you could do so with a config file same as on Linux ~/.ssh/config
host example.com
HostName example.com
IdentityFile ~/.ssh/id_rsa
User git
Don't forget to set the permissions chmod 400 ~/.ssh/id_rsa
Solution 3
Assume the private key file you want to import to git bash is D:/keys folder/myprivatekey
and your Git was installed in D:/Git
(in which folder you would see the binary file git-bash.exe
), open the file D:/Git/etc/ssh/ssh_config
.
Here are some texts in this file:
...
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
...
Simply add a new line and save it:
...
# StrictHostKeyChecking ask
IdentityFile "D:/keys folder/myprivatekey"
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
...
And the key is already added.
Samiul Alam
I am currently working as a Software Engineer at Enosis Solutions. My work focuses on back-end web development. I completed my B.Sc in Engineering majoring in Computer Science from Ahsanullah University of Science and Technology, Dhaka, Bangladesh.
Updated on February 11, 2022Comments
-
Samiul Alam over 2 years
I have an SSH key saved in
D:/keys folder
. I want to add it to my git bash. All the tutorials I found is how to generate SSH key using gitbash and load it to github/gitlab. I generated my SSH key using puttygen. Now I want to add it to my git bash so that I can clone a repository from remote. How can I do that? -
Phate about 4 yearsit works but how to make this permanent? I have to repeat each time I restart git bash
-
Manu about 3 years@Phate, Did you manage to understand how to add this permanently and repeat for every restart