SSH Keys

SSH Key Generation Guide

1

Open Terminal

Open Terminal application

2

Generate ED25519 Key Pair

Run the following command to generate a key. When prompted for the save location, press Enter to use the default path. Then set a passphrase (optional but recommended).

Terminal Command
ssh-keygen -t ed25519 -C "your_email@example.com"
💡 A passphrase adds an extra layer of protection for your private key.
3

Start SSH Agent

SSH Agent manages keys so you don't need to enter your passphrase every time.

Terminal Command
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
4

Copy Public Key

The public key needs to be added to the remote server or Git platform (e.g., GitHub).

Terminal Command
cat ~/.ssh/id_ed25519.pub
💡 Copy the entire output starting from ssh- to the email address.
5

Add Public Key to Remote Server

Use ssh-copy-id to add the public key to a remote server with one command.

Terminal Command
ssh-copy-id user@hostname
6

Verify Connection

Verify that the key configuration is working.

Terminal Command
ssh -T user@hostname
💡 For GitHub: ssh -T git@github.com

SSH Config File Template Generator

Auto-generate ~/.ssh/config configuration

~/.ssh/config
Host myserver
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

Common SSH Commands Reference

Generate Key
ssh-keygen -t ed25519 -C "email"

Generate Ed25519 key pair

View Public Key
cat ~/.ssh/id_ed25519.pub

Display public key content for copying

Copy Public Key
ssh-copy-id user@host

Add public key to remote server

Start Agent
eval "$(ssh-agent -s)"

Start SSH Agent background process

Add Key
ssh-add ~/.ssh/id_ed25519

Add private key to SSH Agent

List Keys
ssh-add -l

List loaded keys

Test Connection
ssh -T git@github.com

Test GitHub SSH connection

Debug Connection
ssh -vT user@host

Verbose mode to troubleshoot connection issues

View Fingerprint
ssh-keygen -lf ~/.ssh/id_ed25519.pub

View public key fingerprint

Change Passphrase
ssh-keygen -p -f ~/.ssh/id_ed25519

Change private key passphrase

Convert Format
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa

Convert key to PEM format

Remote Port Forwarding
ssh -R 8080:localhost:80 user@host

Forward remote port to local

🔒 Security Tips & Best Practices

🔑 Use Ed25519

Ed25519 is more secure and faster than RSA, with shorter keys. Choose Ed25519 unless the target system does not support it.

🛡️ Set a Passphrase

Set a passphrase for your private key. Even if the private key file is leaked, a passphrase prevents attackers from using it directly.

📁 Set Correct Permissions

Private key file permissions should be 600 (chmod 600), and the .ssh directory should be 700. Never share your private key.

🔄 Rotate Keys Regularly

It is recommended to rotate SSH keys every 1-2 years, and immediately after any suspected compromise.

🚫 Disable Password Login

After setting up SSH keys, disable password-based login on the server (PasswordAuthentication no).

📋 Use Separate Keys

Use different keys for GitHub, work servers, and personal servers for easier management and revocation.

SSH Key Generation Guide

Main Features

  • Step-by-step Guide - Guided SSH key pair generation
  • Multi-platform - Linux/macOS, Windows PowerShell, Git Bash
  • Config Generator - Auto-generate SSH config file templates
  • Command Reference - Quick reference for common SSH commands

Use Cases

  • GitHub/GitLab SSH authentication setup
  • Passwordless remote server login
  • DevOps automated deployment
  • Multi-server SSH management

常见问题

相关工具