Git Security SSH

Divya Srinivasan

What is SSH?

SSH (Secure Shell) is a protocol that lets you securely connect to remote computers and services—such as Git repositories—over the internet.

SSH uses a key pair (a public key and a private key) to ensure only you can access your remote resources.

 Key SSH Concepts & Commands



How SSH Keys Work

  • Your public key is like a lock—you share it with servers (e.g., GitHub, GitLab, Bitbucket).
  • Your private key is like the actual key—you keep it safe and never share it.
  • Only the matching private key can unlock what’s secured by the public key.

 Generating an SSH Key Pair

To create a new SSH key pair, run this in your terminal (Linux, macOS, or Git Bash on Windows):
ssh-keygen -t rsa -b 4096 -C "your@email.com"
Follow the prompts to:
  • Choose a file location (press Enter to use the default: ~/.ssh/id_rsa)
  • Set a passphrase (optional but recommended)

 Adding Your Key to the SSH Agent

Load your private key into the SSH agent so Git and other tools can use it:
ssh-add ~/.ssh/id_rsa

Copying Your Public Key

To add your public key to your Git hosting service, copy it using one of these commands:

macOS:

pbcopy < ~/.ssh/id_rsa.pub

Windows (Git Bash):

clip < ~/.ssh/id_rsa.pub

Linux:

cat ~/.ssh/id_rsa.pub
Then, paste the copied key into your account settings on GitHub, GitLab, or Bitbucket.

Listing & Removing Loaded SSH Keys

  • List keys currently loaded:
ssh-add -l
  • Remove a key from the agent:
ssh-add -d ~/.ssh/id_rsa

 Troubleshooting SSH

1.If you see Permission denied:
  • Confirm your public key is added to your Git host.
  • Make sure your private key is loaded (ssh-add -l).
2.Check private key permissions:
chmod 600 ~/.ssh/id_rsa
3.Debug with verbose output:
ssh -vT git@github.com
4.Ensure your Git remote URL starts with git@ (not https://).

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send