Looking to join a great team — open to 186/482 visa sponsorship in Australia. Learn more

How to Generate an SSH Key on macOS (Step-by-Step Guide)

Secure Shell (SSH) keys are an essential tool for developers, sysadmins and anyone managing code repositories. If you’re working with GitHub, Bitbucket or remote servers on a Mac in Australia, you’ll almost certainly need to generate and manage SSH keys. This article will walk you through the process of creating, configuring and testing SSH keys on macOS.

How to Generate an SSH Key on macOS (Step-by-Step Guide)
▶ Play

Table of Contents

What is an SSH key?

An SSH key is a cryptographic key pair (public and private) used to authenticate securely between your Mac and a remote server or service such as GitHub or Bitbucket. Unlike passwords, SSH keys provide stronger security and convenience, especially when working with repositories and automation.

Prerequisites before generating SSH keys

  • Ensure you have macOS Terminal (pre-installed on all Macs).
  • Make sure you have OpenSSH available (macOS includes it by default).
  • Optional: A GitHub or Bitbucket account if you plan to use SSH for repositories.

Step-by-step: Generate SSH key on macOS Terminal

Open Terminal and run the following command:

ssh-keygen -t ed25519 -C "[email protected]"

Explanation of options:

OptionDescription
-t ed25519Specifies the key type (modern and recommended). Use rsa if older systems require it.
-CComment, usually your email for identification.

You’ll be prompted to choose a file location (press Enter to accept the default) and optionally set a passphrase for extra security.

Where to find your SSH keys on macOS

SSH keys are stored in the ~/.ssh/ directory by default. Common files include:

  • id_ed25519 (private key)
  • id_ed25519.pub (public key)

Adding SSH key to the macOS keychain

To make your SSH key automatically available without retyping the passphrase:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Adding SSH key to GitHub on macOS

  1. Copy your public key: pbcopy < ~/.ssh/id_ed25519.pub
  2. Go to GitHub > Settings > SSH and GPG keys.
  3. Click New SSH key, paste the key, and save.

Adding SSH key to Bitbucket on macOS

  1. Copy the public key (same as above).
  2. Go to Bitbucket > Personal settings > SSH keys.
  3. Add the key and confirm.

Testing your SSH connection

Test with GitHub:

ssh -T [email protected]

Test with Bitbucket:

ssh -T [email protected]

Troubleshooting common issues

  • Permissions error: Run chmod 600 ~/.ssh/id_ed25519.
  • SSH agent not running: Start it with eval "$(ssh-agent -s)".
  • Wrong key type: Try generating with -t rsa if older servers don’t support ED25519.

Best practices for managing SSH keys

  • Use ED25519 unless compatibility requires RSA.
  • Always protect private keys with correct file permissions.
  • Consider using a passphrase for sensitive environments.
  • Backup your keys securely but never share private keys.
  • Use different keys for work and personal projects if possible.

Conclusion

Generating an SSH key on macOS is straightforward with Terminal. Once created, you can use the key for GitHub, Bitbucket and other secure connections. Following best practices ensures both convenience and security for Australian developers managing code and infrastructure.

FAQ

How do I generate an SSH key on Mac?
Use Terminal and run ssh-keygen -t ed25519 -C “[email protected]”. Follow the prompts to complete the process.
How to add SSH key to GitHub on Mac?
Copy your public key with pbcopy < ~/.ssh/id_ed25519.pub and paste it in GitHub under Settings > SSH and GPG keys.
How to add SSH key to Bitbucket on Mac?
Copy your public key and add it to Bitbucket under Personal settings > SSH keys.
Where are SSH keys stored on Mac?
By default, in the ~/.ssh/ directory.
How to test if SSH key works on Mac?
Run ssh -T [email protected] or ssh -T [email protected]. If successful, you’ll see a greeting message.
Do I need a passphrase for my SSH key?
A passphrase is optional but adds an extra layer of security. For critical projects, it’s strongly recommended.