This guide provides step-by-step instructions to configure SSH on a Linux system and use it with GitHub.
- Check for Existing SSH Keys
- Generate a New SSH Key Pair
- Add Your SSH Key to the SSH Agent
- Copy the SSH Public Key
- Add Your SSH Key to GitHub
- Test Your SSH Connection
First, check if you already have SSH keys set up on your Linux system.
ls -al ~/.ssh
If you see id_rsa.pub
or id_ecdsa.pub
, you might already have an existing public key. If not, proceed to the next step to generate a new key pair.
To generate a new SSH key pair, use the ssh-keygen
command:
ssh-keygen -t ed25519 -C "your_email@example.com"
-t ed25519
: Specifies the key type. You can also usersa
orecdsa
.-C "your_email@example.com"
: A comment to identify the key.
Follow the prompts. You can press Enter to accept the default file location and create an optional passphrase for added security.
To ensure the SSH agent is running and add your key to it:
eval "$(ssh-agent -s)" # Starts the SSH agent if not running
ssh-add ~/.ssh/id_ed25519 # Replace with your key type if different
Before adding your SSH key to GitHub, you need to copy the public key. Use the cat
command to display the contents of your public key file and copy it to your clipboard.
cat ~/.ssh/id_ed25519.pub # Replace with your key type if different
Select and copy the entire output, ensuring you include the ssh-ed25519
(or similar), the key, and your comment (usually your email).
- Go to GitHub SSH settings.
- Click "New SSH Key".
- Give your key a descriptive title (like "Personal Laptop" or "Work Computer").
- Paste the SSH public key that you copied earlier.
- Click "Add SSH Key".
- GitHub might ask for your account password to confirm the change.
To ensure everything is set up correctly, test your SSH connection to GitHub:
ssh -T git@github.com
If you see a message like "You've successfully authenticated," you're all set! If you encounter any errors, double-check your steps or consult GitHub's troubleshooting documentation.
That's it! You now have SSH set up to securely connect with GitHub. You can now clone, push, and pull repositories without needing to enter your GitHub password each time.