GitHub SSH Key Example: Step-by-Step Tutorial

Logan Jul 13, 2026

Securely connecting to GitHub using SSH is not only faster, but also more convenient and secure than using HTTPS. To achieve this, you'll need to set up an SSH key pair on your local machine and add the public key to your GitHub account. Let's guide you through the process with a practical example.

Setting up SSH Keys for Github, GitLab, and Bitbucket in one windows pc
Setting up SSH Keys for Github, GitLab, and Bitbucket in one windows pc

Before we dive into the details, ensure you have Git and OpenSSH installed on your local system. If not, you can install them using the package manager of your operating system. Now, let's generate your new SSH key pair.

How to Secure Github Access With an SSH Key - Make Tech Easier
How to Secure Github Access With an SSH Key - Make Tech Easier

Generating and Adding Your SSH Key

The first step is to generate a new SSH key pair on your local machine. This pair consists of a private key (which you keep secret) and a public key (which you share with others, like GitHub).

Streamlined Guide: Setting Up SSH and GPG Keys on GitHub
Streamlined Guide: Setting Up SSH and GPG Keys on GitHub

Here's how you can generate a new SSH key pair: 1. Open your terminal. 2. Run the following command to generate a new SSH key (replace "your-email@example.com" with your actual email):

ssh-keygen -t ed25519 -C "your-email@example.com"

Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)
Git & GitHub Cheat Sheet 🔥 | Commands, Workflow, Branching & Version Control (Beginner to Pro)

The command will prompt you to choose a file location. Press Enter to accept the default location (~/.ssh/id_ed25519). You can also add a passphrase for extra security, but it's not mandatory for this example.

Adding Your SSH Key to SSH-Agent

After generating your key, you need to add it to your SSH Agent. This way, your key is loaded automatically when you open a new terminal session. 1. To add your key, run the following command:

Add a SSH Key to Github
Add a SSH Key to Github

eval "$(ssh-agent -s)"

This command starts the SSH Agent in the background and prints its command line. 2. Now, add your key to the agent:

ssh-add ~/.ssh/id_ed25519

the github chat sheet is displayed in this screenshote screen graber
the github chat sheet is displayed in this screenshote screen graber

The SSH Agent will ask for your passphrase if you added one during the key generation step.

Testing Your SSH Connection

an image of a poster with words in the background that say, github doks for finding files
an image of a poster with words in the background that say, github doks for finding files
SSH Troubleshooting Guide for Linux Admins | Fix 13 Common SSH Errors
SSH Troubleshooting Guide for Linux Admins | Fix 13 Common SSH Errors
the github chat sheet is displayed in pink and black
the github chat sheet is displayed in pink and black
Github Cheatsheet
Github Cheatsheet
Arch Linux, Black Arch Linux, Linux Customization, Kali Linux Commands, Kali Linux, Hacking Books, Data Science Learning, Learn Computer Coding, Secret Websites
Arch Linux, Black Arch Linux, Linux Customization, Kali Linux Commands, Kali Linux, Hacking Books, Data Science Learning, Learn Computer Coding, Secret Websites
Github vs Git
Github vs Git
Anton (@therceman) on X
Anton (@therceman) on X
the git chatsheet screen is lit up with orange and green text on it
the git chatsheet screen is lit up with orange and green text on it
How To Stop macOS Sierra From Remembering Your SSH Key Passphrase - TeckLyfe
How To Stop macOS Sierra From Remembering Your SSH Key Passphrase - TeckLyfe
the back side of a purple and black background with text in different languages on it
the back side of a purple and black background with text in different languages on it
the haschat tool poster is shown in purple and orange colors, with an image of
the haschat tool poster is shown in purple and orange colors, with an image of
a black and white arrow symbol on a black background
a black and white arrow symbol on a black background
Assume your GitHub account is hacked, users with weak crypto keys told
Assume your GitHub account is hacked, users with weak crypto keys told
GitHub - epsylon/Smuggler: Smuggler can detect and exploit -HTTP Smuggling- vulnerabilities.
GitHub - epsylon/Smuggler: Smuggler can detect and exploit -HTTP Smuggling- vulnerabilities.
How to Generate A Public/Private SSH Key in Linux - Make Tech Easier
How to Generate A Public/Private SSH Key in Linux - Make Tech Easier
How to Generate an SSH Key on Linux
How to Generate an SSH Key on Linux
Tech Dev Notes on X: "Grok Build Slash commands in CLI https://t.co/73tp2GsfAj" / X
Tech Dev Notes on X: "Grok Build Slash commands in CLI https://t.co/73tp2GsfAj" / X
The Ultimate Git Commands Cheat Sheet for Developers 🚀💻 #git #command #code
The Ultimate Git Commands Cheat Sheet for Developers 🚀💻 #git #command #code
GitHub - mishakorzik/AllHackingTools: All-in-One Hacking Tools For Hackers! And more hacking tools! For termux.
GitHub - mishakorzik/AllHackingTools: All-in-One Hacking Tools For Hackers! And more hacking tools! For termux.
an image of a computer screen with the text hackr login form
an image of a computer screen with the text hackr login form

Before proceeding, let's ensure your SSH key is working correctly. Run the following command:

ssh -T git@github.com

If everything works fine, you should see a "Hi {Your Username}! You've successfully authenticated, but GitHub does not provide shell access." message.

Adding Your SSH Key to GitHub

Now that your SSH key is set up on your local machine, it's time to add it to your GitHub account. This enables GitHub to recognize you when you authenticate with your SSH key.

To add your key, follow these steps:

1. Navigate to https://github.com/settings/keys in your web browser. 2. Click "New Key." 3. Give your key a title, e.g., your machine's name or a description of the key's purpose. 4. In the "Key" field, paste the content of your public SSH key (found in the `~/.ssh` directory where you generated the key). To find this, open the key file (id_ed25519.pub) in a text editor and copy everything. 5. Click "Add Key" to save it.

Using Your SSH Key with Git

Finally, you need to tell Git to use your SSH key for SSH communication. This can be done in your `~/.gitconfig` file: 1. Open your `~/.gitconfig` file in a text editor. If the file doesn't exist, create it.

2. Add the following content to the file:

[user] name = Your Name email = your.email@example.com signingkey = /path/to/your/id_ed25519

3. Save and close the file. Now, your SSH key is associated with your Git configurations.

Pushing Your First Repository

Now you can push your first repository to GitHub using SSH. Here's an example of how to do this:

1. Initialize a new Git repository: git init

2. Add your new files: git add .

3. Commit your changes: git commit -m "Initial commit"

4. Create a new repository on GitHub. 5. Connect your local repository to your new GitHub repository: git remote add origin git@github.com:yourusername/your-repo-name.git 6. Push your local repository to GitHub: git push -u origin master

And that's it! You've successfully added your SSH key to GitHub and pushed your first repository using SSH. As you continue to use Git and GitHub, using SSH will make your workflow faster and more secure.

Happy coding! Remember to keep your private SSH key safe and secret. Never share it with anyone. If you suspect your key has been compromised, revoke it from GitHub and generate a new one.