Connecting to a Server with an SSH Key (Windows, Mac, Linux)
Last updated: 23 September 2026
An SSH key lets you connect to a server with a cryptographic key pair instead of a password. Passwords are guessable and open to brute force; an SSH key is practically unbreakable. This guide covers generating a key pair, adding it to the server and disabling password login, for Windows, macOS and Linux.
How does an SSH key work?
You have a key pair:
- Private key (
id_ed25519) — stays with you, never shared - Public key (
id_ed25519.pub) — copied to the server
When you connect, the server sends a "challenge" using the public key; you sign it with the private key. The private key never leaves your computer.
1. Generate a key pair
Terminal (macOS/Linux) or PowerShell (Windows 10+):
ssh-keygen -t ed25519 -C "yourname@computer"
- File location: press Enter (default
~/.ssh/id_ed25519). - Passphrase: a password protecting the private key. Strongly recommended — if your computer is stolen, the key is still safe.
ed25519 is modern and secure. If you are dealing with a very old system, use -t rsa -b 4096.
2. Add the public key to the server
Easy way (macOS / Linux)
ssh-copy-id user@SERVER_IP
Asks for the password once, then adds the key.
Windows / no ssh-copy-id
Display the public key and copy it:
# Windows PowerShell
Get-Content ~/.ssh/id_ed25519.pub
# macOS / Linux
cat ~/.ssh/id_ed25519.pub
Connect to the server and add it:
ssh user@SERVER_IP
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-ed25519 AAAA... yourname@computer" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
If the server asks for a key at first setup
Many providers let you paste your public key while creating the server. This is the cleanest way — the server comes up passwordless directly.
3. Test the connection
ssh user@SERVER_IP
If you can log in without being asked for a password (or only for the key passphrase), it works.
4. Disable password login
sudo nano /etc/ssh/sshd_config
Set these lines:
PasswordAuthentication no
PermitRootLogin prohibit-password
PubkeyAuthentication yes
sudo systemctl restart ssh
Now only computers that have the key can connect to the server.
Multiple computers / a team
Each person/computer should have its own key pair. You add their public keys to ~/.ssh/authorized_keys as separate lines. To revoke someone's access, deleting that line is enough.
SSH config file (convenience)
Get rid of long commands with ~/.ssh/config:
Host arcnar-web
HostName 203.0.113.10
User arcnar
IdentityFile ~/.ssh/id_ed25519
Now you only need to type ssh arcnar-web.
Common errors
- "Permission denied (publickey)": the public key is not on the server, is on the wrong user, or the
authorized_keys/.sshpermissions are wrong (must be 700 and 600). - Still asks for a password: run
ssh -v user@ipfor verbose output; it shows which key is being tried. - Key not found on Windows: make sure the OpenSSH client is installed (Settings → Optional Features).