Secure Your Code: Add SSH Key to GitHub

Learn how to securely connect to GitHub using SSH keys, a passwordless authentication method essential for developers.

2 min read
Illustration of a padlock securing a GitHub logo, representing secure access.
SSH keys provide a vital layer of security for developers connecting to GitHub.· Github Blog

Securing your connection to code repositories is paramount. GitHub offers SSH keys as a robust, passwordless authentication method. This process involves generating a unique pair of cryptographic keys on your local machine: a private key that remains confidential and a public key distributed to services like GitHub. When you initiate an action, such as pushing or pulling code, your local machine uses the private key to cryptographically prove your identity to GitHub, which verifies it against the stored public key. This ensures only you can interact with your repositories.

Generating and Adding Your SSH Key

To begin, open your terminal and generate a new SSH key pair using the command ssh-keygen -t ed25519 -C "[email protected]", replacing the placeholder with your GitHub-associated email. Accept the default file location by pressing Enter, and then set a strong passphrase for added security. The system will not display your passphrase as you type.

Next, add your SSH key to the ssh-agent, a program that manages your keys and avoids repeated passphrase entries. Execute ssh-add ~/.ssh/id_ed25519, entering your passphrase when prompted.

Related startups

To get the public key content for GitHub, run cat ~/.ssh/id_ed25519.pub in your terminal. Copy the entire output.

Navigate to your GitHub account settings. In the left-hand sidebar, select 'SSH and GPG keys'. Click the 'New SSH key' button. Provide a descriptive title for your key (e.g., 'work-laptop') in the 'Title' field and paste the copied public key into the 'Key' box. Finally, click 'Add SSH key'.

This setup enables secure, authenticated communication between your machine and GitHub, streamlining your development workflow.

© 2026 StartupHub.ai. All rights reserved. Do not enter, scrape, copy, reproduce, or republish this article in whole or in part. Use as input to AI training, fine-tuning, retrieval-augmented generation, or any machine-learning system is prohibited without written license. Substantially-similar derivative works will be pursued to the fullest extent of applicable copyright, database, and computer-misuse laws. See our terms.