SSH (Secure Shell) is a protocol used to securely communicate with remote servers. In Git, SSH is commonly used to authenticate and encrypt connections between your computer and remote repositories like GitHub, GitLab, or Bitbucket.
Using SSH enhances security by eliminating the need to enter a password every time you push or pull changes. Instead, it uses a secure key-pair system: a private key (kept on your computer) and a public key (stored on the server).
Before creating a new SSH key, check if you already have one:
ls -al ~/.ssh
If you see files like id_rsa
and id_rsa.pub
, you already have SSH keys. Otherwise, proceed to the next step.
If you don’t have an existing SSH key, generate one:
Use the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-t rsa
: Specifies the key type as RSA.-b 4096
: Sets the key length to 4096 bits for extra security.-C
: Adds a label (your email) to identify the key.Enter
to save it in the default directory (~/.ssh/id_rsa
).C:\Users\username\.ssh
The SSH agent manages your private keys. Add your key to it:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
You now need to share your public key with your Git server (e.g., GitHub).
Display the public key:
cat ~/.ssh/id_rsa.pub
Go to your Git hosting platform:
Paste the public key, give it a name, and save.
Add copied content to the Github Account
Click on New SSH Key
Paste the SSH Key in your Github account and click on Add SSH Key
Using SSH with Git not only secures your connection but also simplifies the authentication process. By following the steps outlined here, you can enhance your Git security and improve your workflow. For advanced users, managing multiple keys and periodically rotating them further strengthens your setup. Happy coding !❤️