• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Android
  • Computer Science
  • GitHub
  • Mac OS
  • Programming
  • How To
  • Windows
CTech

CTech

Your Guiding Technology

You are here: Home / GitHub / How to Generate an SSH Key on macOS: A Step-by-Step Guide

How to Generate an SSH Key on macOS: A Step-by-Step Guide

Update August 18, 2024 by CentralTechDev

SSH keys provide a secure way of logging into a remote server without the need for a password. If you’re using GitHub, creating an SSH keygen on your Mac allows you to securely connect to your repositories without entering your credentials each time. This guide will walk you through the process of generating an SSH keygen and configuring it with GitHub.

Table of Contents

Toggle
  • Step-by-Step to Generate an SSH Key GitHub
    • Step 1: Open Terminal
    • Step 2: Generate a New SSH Key
    • Step 3: Add the SSH Key to the SSH-Agent
    • Step 4: Copy the SSH Key to Your Clipboard
    • Step 5: Add Your SSH Key to GitHub
      • Method 1 : SSH and GPG Keys (Account-wide SSH Keys)
      • Method 2 : Deploy Keys (Repository-specific SSH Keys)
    • Step 6: Test the SSH Connection
  • Conclusion

Step-by-Step to Generate an SSH Key GitHub

Step 1: Open Terminal

To begin, you’ll need to open the Terminal on your Mac. You can find Terminal in Applications » Utilities » Terminal, or you can search for it using Spotlight by pressing Command + Space and typing “Terminal.”

Step 2: Generate a New SSH Key

In the Terminal, enter the following command to generate a new SSH key:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Here’s what each part of this command means:

  • ssh-keygen: This is the command that generates a new SSH key.
  • -t rsa: Specifies the type of key to create, in this case, an RSA key.
  • -b 4096: Sets the number of bits in the key to 4096. A higher bit value means a more secure key.
  • -C “your_email@example.com”: Adds a label to the key, typically your email address, to help identify it.

After entering this command, you will be prompted to save the key:

  • Save Location: Press Enter to accept the default location (/Users/your_username/.ssh/id_rsa).
  • Passphrase: You will be asked to enter a passphrase for additional security. You can choose to leave it empty by pressing Enter, but setting a passphrase is recommended.
create ssh key generate

Step 3: Add the SSH Key to the SSH-Agent

To manage your SSH keys, you’ll need to add the newly generated SSH key to the SSH agent. Run the following command in Terminal:

ssh-add ~/.ssh/id_rsa

This command loads your SSH private key into the SSH agent, making it available for authentication.

Step 4: Copy the SSH Key to Your Clipboard

Next, you need to copy the SSH public key to your clipboard so you can add it to GitHub:

pbcopy < ~/.ssh/id_rsa.pub

This command copies the contents of your public key file (id_rsa.pub) to the clipboard.

add ssh keygen

Step 5: Add Your SSH Key to GitHub

Choose one of the following two methods :

Method 1 : SSH and GPG Keys (Account-wide SSH Keys)

Use Account-wide SSH Keys if you are a developer who needs to work on multiple repositories and prefers the convenience of managing a single key. This method is ideal for users who need broad access across their GitHub account.

  1. Go to your GitHub account settings.
  2. And under “SSH and GPG keys,” click New SSH Key.
  3. Give your key a descriptive title (e.g., “Personal Laptop Key”) and paste the SSH key from your clipboard into the key field, then click Add SSH Key.
  4. Done
add ssh key to account

Method 2 : Deploy Keys (Repository-specific SSH Keys)

Use Deploy Keys if you need to grant access to a specific repository, particularly for automation tools, CI/CD systems, or when you’re working in an environment that requires strict access control. Deploy keys provide a secure, repository-specific access method that minimizes the risk of overprivileged access

Now that your SSH key is copied to your clipboard, you can add it to your GitHub account:

  1. Log in to GitHub : Visit GitHub and log in to your account.
  2. Navigate to Deploy Keys : Open your Repository and go to Settings. In the left sidebar, click Deploy keys.
  3. Add Deploy Key : Click the Add deploy key button.
  4. Paste Your Key : In the “Title” field, enter a name to identify this key (e.g., “MyKey”), and paste the SSH key you copied in Step 4 into the “Key” field.
  5. Don’t forget to tick ‘Allow write access‘.
  6. Save : Click Add key to save your new SSH key.
add deploy keys

Here, for more detail about the Differences Between SSH Key Storage Methods on GitHub: SSH and GPG Keys vs. Deploy Keys.

Step 6: Test the SSH Connection

Finally, you should test your SSH connection to ensure everything is set up correctly. Run the following command in Terminal:

ssh -T git@github.com

If this is your first time connecting, you may see a message asking if you want to continue connecting. Type yes and press Enter.

If your setup is correct, you should see a message like this:

Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.

This message confirms that your SSH key is working correctly and you can now interact with GitHub repositories securely.

test connection github

Conclusion

Creating an SSH keygen on macOS is a straightforward process that significantly enhances the security and convenience of your GitHub interactions. By following the steps outlined in this guide, you can generate a secure SSH key, add it to GitHub, and verify the connection—all within a few minutes.

Remember, using SSH keys is a best practice for secure access to remote servers and services like GitHub. Keep your private key safe, and enjoy the hassle-free authentication that SSH keys provide!

Filed Under: GitHub, Mac OS Tagged With: git, github, key, macos, ssh

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

More to See

How to Fix the “You Shut Down Your Computer Because of a Problem” Error on macOS

September 5, 2024 By CentralTechDev

missing file lightroom

How to Relink Missing or Offline Files in Adobe Lightroom Classic: A Step-by-Step Guide

August 21, 2024 By CentralTechDev

Tags

adobe android battery cloud cpanel creative domain files git github hosting key lightroom macos mds_store missing problem relink repository search shutdown spotlight ssh tutorial

Footer

Text Widget

This is an example of a text widget which can be used to describe a particular service. You can also use other widgets in this location.

Examples of widgets that can be placed here in the footer are a calendar, latest tweets, recent comments, recent posts, search form, tag cloud or more.

Sample Link.

Recent

  • Connect cPanel Git Version to GitHub Private Repository
  • How to Fix the “You Shut Down Your Computer Because of a Problem” Error on macOS
  • How to Relink Missing or Offline Files in Adobe Lightroom Classic: A Step-by-Step Guide
  • 30 Key Terms and Concepts in Git and GitHub: A Developer’s Guide
  • What is Git and GitHub? A Comprehensive Guide

Search

Tags

adobe android battery cloud cpanel creative domain files git github hosting key lightroom macos mds_store missing problem relink repository search shutdown spotlight ssh tutorial

Copyright © 2025 · CentralTech.Dev