SSH Keys From Scratch: Your Machine to Your Servers
Create a key, put it on a server, name your servers in ~/.ssh/config, and connect with ssh prod instead of an IP address. Ends with a machine that logs in without passwords and a config you can copy to the next one.
Prerequisites
- A terminal on your own machine (macOS, Linux, or Windows with WSL or Git Bash)
- A server you can currently reach, with a password or an existing key
- No prior SSH knowledge needed
If a key exists, do not generate over it. Anything that trusts it, servers and GitHub alike, would stop letting you in.
Check Whether You Already Have an SSH Key
A pair named id_ed25519 and id_ed25519.pub means you already have a key and can skip the next step.
Generate ed25519 SSH key
Fix ~/.ssh Permissions
Run this even on a fresh key. It is the fix for most "it keeps asking for my password" reports.
Load a Key into the SSH Agent
ssh-add -l should now list your key fingerprint. An empty list means the agent is not running.
Two ways to put the key on the server
# الأسهل، إن كان لديك دخول بكلمة مرور: الخطوة التالية # وإن كان الدخول بكلمة المرور معطلاً، أو تلصق عبر لوحة تحكم: الخطوة التي تليها
ssh-copy-id does it in one command when password login still works. The manual step after it is for servers where it does not, or for pasting into a provider panel.
Copy SSH Key to Remote Server
It asks for your password one last time. After this, that password is no longer part of your workflow.
Only the .pub file is ever shared. The file without .pub is the private key and never leaves your machine.
Print Your Public Key to Paste It Somewhere
The alternative route: copy this line and paste it into GitHub, cPanel, or your provider dashboard.
Test an SSH Connection Without Opening a Shell
It should print OK and the hostname without asking for anything. If it asks for a password, go back to the permissions step.
Set Up ~/.ssh/config for Several Servers
This is the step that changes your day: ssh prod now replaces the address, the user and the port.
Use a Different Key per Account or Host
Optional, and the reason most people meet ~/.ssh/config in the first place: a work GitHub account and a personal one on the same laptop.
SSH via Jump Host (Bastion)
For a server with no public address: reach it through a bastion in one command.
Debug a Refused SSH Login (Verbose Mode)
Keep this one. When a login is refused, it names the cause instead of leaving you guessing.
Only after the previous steps succeed, and keep your current session open while you test a second one.
Disable Root SSH Login
The payoff: once key login is proven, turning off passwords and root login removes the attack surface brute force relies on.