In this article, we will see how to configure SSH keys in git for windows.
What is SSH?
SSH (secure shell) is a protocol used for secure communication between two computers. SSH uses a key-pair also known as public key and private key for the secure authentication between the client & server.
The public key is stored on the server side whereas the private key is stored on the client side (Local machine). During the connection, server uses public key to authenticate with the client i.e. local machine.
Generating SSH key pair
To work with git, we will need to generate an SSH key pair.
Install the git from the following link
After installing the git, we will get a Git bash terminal. Run the following command in the git bash terminal.
ssh-keygen -t rsa -b 4096 -C "[email protected]"
After entering the above command, we will be prompted to enter a file and passphrase for the private key. We need this private key file to configure the git. Now, we will get a new RSA key pair with a length of 4096 bits and it will be associated with the above specified email address.
On windows, the default location for the SSH keys are
%userprofile%\.ssh\. In file explorer, open the above directory and you will see two files i.e.
id_rsa.pub. These are the private and public key files.
On Linux, the default location for SSH keys are
Configuring the git with SSH keys in windows:
Now, we need to configure the git with SSH keys that we generated in the previous step. Run the following command in the git bash:
Please note, id_rsa is the default file name of the private key. If you have provided a different name while generating the private key, please use the same name.
Configuring the git server with public key
Finally, we need to configure the git server with public key. Open the id_rsa.pub file and copy its contents.
- Login to your git account.
- Open the account settings & navigate to SSH keys section.
- Click the “Add SSH key” button and paste the public key into the text box and save the changes.