SSH keys are a method for securely connecting to remote computers and servers over the internet. SSH stands for Secure Shell, and it's a protocol that creates an encrypted connection between your computer and another system. Instead of typing a password every time you want to access a server or push code to a repository, SSH keys allow you to authenticate automatically and securely.
Learn About South Carolina Vehicle Registration Renewal →
SSH keys work as a pair: a public key and a private key. The public key is like a lock that you share with services like GitHub. The private key is like the only key that can open that lock, and you keep it on your computer. When you try to connect to GitHub or another service using SSH, your computer proves it has the matching private key without ever sending the key itself across the internet. This method is far more secure than password authentication for several reasons.
GitHub reported in 2023 that developers who use SSH keys experience fewer account compromise incidents compared to those relying solely on password-based authentication. According to GitHub's own documentation, SSH authentication eliminates the need to enter credentials repeatedly, which reduces the likelihood of passwords being intercepted or guessed. Major technology companies including Google, Facebook, and Microsoft all recommend SSH keys as a primary authentication method for developers.
Developers use SSH keys because they provide convenience without sacrificing security. Once you set up an SSH key, you can push code to repositories, pull updates, and perform other Git operations without repeatedly entering your password. This workflow is especially valuable for developers who make dozens of commits per day. Additionally, SSH keys allow different applications and devices to authenticate separately. You might have one SSH key for your laptop, another for your work desktop, and a third for a CI/CD server. If one key is compromised, you can revoke just that key without affecting your other connections.
Practical Takeaway: SSH keys provide a more secure and convenient authentication method than passwords. Understanding how they work helps you protect your code repositories and streamline your development workflow.
Generating an SSH key involves using terminal or command-line tools on your computer. The process differs slightly depending on whether you use Windows, macOS, or Linux, but the underlying concept remains the same. You'll use a tool called ssh-keygen, which comes built-in on macOS and Linux systems. Windows users have access to this tool through Git Bash, PowerShell, or the Windows Subsystem for Linux.
Astrology Signs and Birth Dates in May →
On macOS and Linux, open your terminal application and enter the command ssh-keygen -t ed25519 -C "your.email@example.com". Replace "your.email@example.com" with the email address associated with your GitHub account. This command creates a new SSH key using the Ed25519 algorithm, which is currently recommended by security experts for its balance of security and performance. The algorithm option (-t ed25519) specifies the type of cryptographic method used to generate the key. If your system doesn't support Ed25519, you can use ssh-keygen -t rsa -b 4096 as an alternative.
After entering the command, the system will ask you where to save the key. The default location is usually ~/.ssh/id_ed25519, which is a hidden folder in your home directory. Pressing Enter accepts this default location. Next, you'll be prompted to enter a passphrase. This is an additional layer of security—a password that protects your private key if someone gains access to your computer. You can leave this blank if you prefer, but adding a passphrase is considered a security best practice. Choose something you'll remember, as you'll need to enter it when using the key.
Windows developers should use Git Bash, which provides a Unix-like environment on Windows. After installing Git for Windows, right-click in any folder and select "Git Bash Here," or open it through your Start menu. Then use the same ssh-keygen commands as macOS and Linux users. Windows users can also use PowerShell 7 or newer, which now includes native SSH capabilities. After generating your keys, you'll see a confirmation message showing where your keys were saved and a fingerprint—a unique identifier for your key pair.
Practical Takeaway: Use ssh-keygen with the Ed25519 algorithm to generate a secure key pair, save it in the default location, and consider adding a passphrase for additional protection.
Once you've created your SSH key pair, you need to add the public key to your GitHub account. Your private key stays on your computer, but your public key tells GitHub that requests coming from your computer are legitimate. To add your public key, you first need to view its contents. On macOS and Linux, use the command cat ~/.ssh/id_ed25519.pub to display your public key. Copy everything that appears—the entire block of text starting with "ssh-ed25519" and ending with your email address.
Get Your Free Capital One Card Cancellation Guide →
Log into your GitHub account and navigate to Settings, which you'll find by clicking your profile picture in the top-right corner of any GitHub page. In the Settings menu, look for "SSH and GPG keys" in the left sidebar. Click "New SSH key" to add your key. Give your key a descriptive title that helps you remember where it's used—for example, "MacBook Pro Work" or "Desktop Linux". Then paste your public key into the large text field. The key should have no extra spaces or line breaks. Click "Add SSH key" to save it to your account.
GitHub allows you to add multiple SSH keys to a single account. This is particularly useful when you work across different devices. A developer might add keys for their laptop, desktop computer, and work machine, all to the same GitHub account. Each key pair remains independent, so if someone steals your laptop, you can remove just the laptop's key from GitHub without affecting your other devices. GitHub displays when each key was last used, which helps you identify old keys that can be safely removed.
When adding a key, make sure you're adding the public key (the one ending in .pub), never the private key. Adding your private key to GitHub or any other service defeats the entire purpose of SSH security. Your private key should remain only on your personal devices. If you accidentally share your private key, you should delete the corresponding public key from GitHub and all services, then generate a new key pair.
Practical Takeaway: Add your public key to GitHub through Settings, use a descriptive title, and verify you're copying the .pub file, not your private key.
After adding your public key to GitHub, you should test whether the connection works properly. This verification step ensures everything is configured correctly before you start relying on SSH for your Git operations. Open your terminal or Git Bash and enter the command ssh -T git@github.com. The -T flag means you're testing the connection without requesting a terminal session.
Learn How Social Security Disability Affects Food Stamps →
If this is your first time connecting to GitHub via SSH, your system will ask whether you trust GitHub's server. You'll see a message asking if you want to continue connecting. Type "yes" and press Enter. Your system is verifying GitHub's identity to prevent man-in-the-middle attacks. If everything is configured correctly, you'll see a message like "Hi [your-username]! You've successfully authenticated, but GitHub does not provide shell access." This confirms your SSH key is working properly with GitHub.
If you set a passphrase when creating your key, you might be prompted to enter it. Some developers find this repetitive and prefer to use an SSH agent, which is a program that stores your decrypted key in memory during your session. On macOS, the SSH agent runs automatically and remembers your key's passphrase while your computer is on. On Linux, you may need to start the agent manually with eval "$(ssh-agent -s)" and then add your key with ssh-add ~/.ssh/id_ed25519. Windows users with OpenSSH can configure the SSH agent to start automatically through Services management.
If the connection fails, check several things: verify that you copied your public key correctly without extra spaces, confirm that you're using the right GitHub username in the ssh-keygen command, and make sure your private key file has the correct permissions (it should be readable only by you, not by other users). On macOS and Linux, you can set permissions with chmod 600 ~/.ssh
This guide is for general information only and is not medical, financial, legal, or other professional advice. For decisions specific to your situation, consult a qualified professional. See our Editorial Policy.