How to configure SSH keys in GIT


Configuring SSH keys in Git allows you to authenticate with Git servers without having to enter your username and password every time. Here are the steps to configure SSH keys in Git:

  • Check if you already have an SSH key pair by running the following command in your terminal:If you see files named id_rsa and id_rsa.pub, you already have an SSH key pair. Otherwise, you will need to create one.
  • Open a terminal and run the following command to check if you already have an SSH key pair:
$ ls -al ~/.ssh
  • If you need to create an SSH key pair, run the following command:This command will create an SSH key pair with the specified email address.
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
  • Follow the prompts to save the SSH key pair to the default location and set a passphrase.
  • Once you have an SSH key pair, you need to add the public key to your Git account. Copy the public key by running the following command:
$ cat ~/.ssh/id_rsa.pub
  • Log in to your Git account and navigate to your account settings.
  • Add the public key to your Git account by pasting the contents of the id_rsa.pub file into the “SSH keys” section of your account settings.
  • Test your SSH connection to the Git server by running the following command:
$ ssh -T [email protected]
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
  • This message indicates that your SSH connection to the Git server was successful and you are now authenticated using your SSH key.

Now that you have set up SSH keys in Git, you can use Git commands without having to enter your username and password every time.

Now that you have set up SSH keys in Git, you can use Git commands without having to enter your username and password every time. For example, you can clone a Git repository using SSH by running the following command:

$ git clone [email protected]:username/repository.git

This command will clone the repository using your SSH key for authentication.

Thanks for reading