Quite often, we find ourselves in need of a secure and efficient way to connect to our GitHub remote repositories. This is where SSH (Secure Shell) comes into play, making a secure channel for Data transmission between your local machine and your GitHub account. In this tutorial, we will guide you through the process of setting up Git with SSH on your machine.

First, let's clear up some basics. SSH allows us to securely control our server over the internet and works perfectly for connecting to GitHub. The process involves creating your SSH key pair - a public and a private key - and adding the public key to your GitHub account. Here's how you can do that:

Generating Your SSH Key Pair
Begin by opening your terminal or Git Bash, then type in the following command to generate your SSH key pair:

ssh-keygen -t ed25519 -C "your_email@example.com"
This command generates a new 256-bit SSH key using the ed25519 algorithm, a fast and secure key type. Replace "your_email@example.com" with your actual email.

Specifying the Key Location
You will be prompted to specify a file location to save the key. The default location is typically in a .ssh folder in your home directory. For simplicity, press Enter to accept the default location.
After saving the key, you will be asked to enter a secure passphrase to protect your key. This extra layer of security ensures no one can access your SSH key even if they gain unauthorized access to your private key.

Copying the SSH Public Key
Now that you have your SSH key pair, you need to copy the public key and add it to your GitHub account. Type in the following command to copy your public key:
pbcopy < ~/.ssh/id_ed25519.pub

If you're using Windows, the equivalent command is:
Get-Clipboard (Get-Content ~/.ssh/id_ed25519.pub)




















Adding Your SSH Key to GitHub
Now that you've copied your public key to the clipboard, it's time to add it to your GitHub account. Go to GitHub and follow these steps:
1. Click on your profile picture at the top right corner of the page.
2. Click on "Settings". In the sidebar, click on "SSH and GPG keys".
3. Click on the green button "New SSH key" to generate a new key.
4. Paste your key in the "Key" field, and provide a title for your key to help you recognize it.
Testing Your SSH Connection
After adding your SSH key to GitHub, it's time to test the connection. Run the following command in your terminal:
ssh -T git@github.com
If everything is set up correctly, you should see a message stating, "Hi [Your Username]! You've successfully authenticated, but GitHub does not provide shell access."
Setting up SSH for Git in your Repository
The final step is to set up Git to use your SSH keys when trying to push or pull from your repositories. Use the following command in your terminal:
git remote set-url origin git@github.com:[YourUsername]/[YourRepositoryName].git
Replace [YourUsername] and [YourRepositoryName] with your actual GitHub username and repository name.
That's it! You've now successfully set up SSH for Git on your machine. No more typing in your password every time you push or pull from your repositories. Happy coding!