Creating Public/Private Keys
Generating an SSH Key and Copying It to a Host
1. Generate the key (Linux, macOS, and Windows)
The same command works on all three systems:
ssh-keygen -t ed25519 -C "your_comment"
This creates two files:
id_ed25519— your private key (never share this)id_ed25519.pub— your public key (this is what gets copied to the host)
On Linux and macOS they are saved in ~/.ssh/. On Windows they are saved in %USERPROFILE%\.ssh\.
2. Copy the public key to the host
Linux and macOS:
ssh-copy-id user@host
Windows (PowerShell):
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@host "cat >> ~/.ssh/authorized_keys"
Windows (Command Prompt):
type %USERPROFILE%\.ssh\id_ed25519.pub | ssh user@host "cat >> ~/.ssh/authorized_keys"
3. Connect
ssh user@host
You should now log in without a password.
Notes
- The OpenSSH client ships by default with Windows 10/11 and current macOS. On Windows, if it is missing, enable it under Settings > Optional Features.
ed25519is preferred. Usessh-keygen -t rsa -b 4096only if the host is too old to support ed25519.- If the remote
~/.sshdirectory does not exist yet, create it first with the correct permissions:mkdir -p ~/.ssh && chmod 700 ~/.ssh, and theauthorized_keysfile should bechmod 600.