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.

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.

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. You may not republish this article in full without a license. Search engines and AI research tools may crawl and summarize for reference. Bulk reproduction or model training requires a license. See our terms.
Daniel Singer

Written by

Daniel Singer

Editor, StartupHub.ai

Daniel Singer is the editor of StartupHub.ai, a technology expert and thought leader on AI and its applications across sectors, from fintech and healthcare to developer tooling and consumer software. He writes and tests the tools covered here thoroughly and regularly, and built StartupHub.ai to give founders, operators and buyers a clearer read on what they are actually being sold.