SSH key authentication allows you to connect to remote servers securely without entering a password each time.
This guide explains how to create an SSH key pair, install the public key on a remote server, and test the connection.
Before generating a new one, check if an SSH key already exists on your system.
ls -l ~/.ssh
ls $env:USERPROFILE\.ssh
If you see files like id_ed25519.pub or id_rsa.pub, you already have a key and can skip to Step 4.
ssh-keygen -t ed25519 -C "your_email@example.com"
If ed25519 is not supported on your system, use RSA:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-keygen -t ed25519 -C "your_email@example.com"
When prompted:
~/.ssh/id_ed25519 or C:\Users\<User>\.ssh\id_ed25519).ls -l ~/.ssh/id_ed25519*
ls $env:USERPROFILE\.ssh\id_ed25519*
You should see two files:
id_ed25519 → private key (keep it secret)id_ed25519.pub → public key (can be shared with servers)ssh-copy-id user@remote_host
Example:
ssh-copy-id marek@192.168.2.150
ssh-copy-id is unavailable)cat ~/.ssh/id_ed25519.pub | ssh user@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@remote_host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Try logging in:
ssh user@remote_host
If everything is configured correctly, SSH should connect without asking for a password.
If you used a passphrase and don’t want to enter it every time:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
Never share your private key (id_ed25519).
Always use strong file permissions for your SSH directory:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
Use a unique key pair for each device if possible.
| Step | Action | Command |
|---|---|---|
| 1 | Check if key exists | ls ~/.ssh |
| 2 | Generate new key | ssh-keygen -t ed25519 -C "email@example.com" |
| 3 | Copy key to server | ssh-copy-id user@host |
| 4 | Test connection | ssh user@host |