SSH Key Gen & Examples
SSH Key-Gen Examples
The Right Way for Forgejo server
Generating a unique key for each machine gives you full control over access permissions:
Instant Revocation: If you lose a laptop, you can log into Forgejo and instantly delete just that one key. Your desktop and other development environments will continue working without interruption.
Independent Access: Your machine identities remain distinct and secure.
🛠️ Best Workflow:
Naming and Adding KeysTo easily track your devices, use a clear device-naming pattern in the comment section of the SSH generator command.
- On your Laptop terminal:
ssh-keygen -t ed25519 -C "username@laptop-macbook"- On your Desktop terminal:
ssh-keygen -t ed25519 -C "username@desktop-linux"- Adding them to Forgejo:
Copy the public keys (cat ~/.ssh/id_ed25519.pub) and add them into your Forgejo:
Dashboard ➔ Settings ➔ SSH / GPG Keys
Give them descriptive titles matching the comments:
Title: Macbook Pro (Laptop)
Title: Linux Workstation (Desktop)
Forgejo supports an unlimited number of SSH public keys per user profile.
It will evaluate incoming push attempts against all registered keys to authorize access securely.Standard client - server SSH key pair generation & setup
Set up SSH Key-Based Authentication.
This works identically on both Linux and macOS. Instead of a password, your computer will use a secure cryptographic key pair to prove its identity to the target server.
Step 1: Generate an SSH Key Pair (On your local machine)
If you don’t already have an SSH key pair on your machine, open your terminal and run this command:
ssh-keygen -t ed25519 -C "hugo-deploy"• What to do: Press Enter to accept the default file location. When it asks for a passphrase, leave it blank (press Enter twice).
Warning
If you add a passphrase, your script will prompt you for that passphrase instead of a password, defeating the automation.
Step 2: Copy the Public Key to your Production Server
You need to send the public half of your key to the web server so it recognizes your computer.
On Linux (and most macOS machines):
Run the built-in utility ssh-copy-id. Replace your_username and your.server.ip.or.domain with your server’s actual details:
ssh-copy-id -p 22 your_username@your.server.ip.or.domain(You will be asked for your server password one last time to authorize the transfer).
If ssh-copy-id is missing on macOS:
If your Mac doesn’t have that command installed, you can achieve the exact same result by running this single string instead:
cat ~/.ssh/id_ed25519.pub | ssh -p 22 your_username@your.server.ip.or.domain "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"Step 3: Test the Connection
Before running your script, verify that the password prompt is gone by attempting a manual connection:
ssh -p 22 your_username@your.server.ip.or.domainIf it drops you straight into the server’s terminal without asking for a password, it’s working perfectly! Type exit to return to your local machine.