Skip to content

SSH Public Key Authentication Client Setup (Windows/Linux)

This article explains how to configure SSH public key authentication on the client side for secure server access. The instructions apply to both Windows and Linux environments.

  • SSH client is pre-installed (Windows 10 or later, Linux default)
  • The target server allows public key authentication
  • The user account exists on the server

SSH supports several key types, such as RSA, ECDSA, and Ed25519. The following table compares their characteristics, recommended use cases, and compatibility.

Key TypeFeaturesRecommended UseCompatibility
RSAWidely used, adjustable key length, high versatilityLegacy systems or high-compatibility environmentsVery High
ECDSAUses elliptic curve cryptography, faster with shorter keysPerformance-oriented environmentsModerate
Ed25519Modern standard, fast, highly secure, small key sizeNew deployments, security-critical systemsSupported on OpenSSH 6.5+

Recommendation: Ed25519 is the preferred standard. It provides better security and performance, while RSA remains widely used for compatibility.

The following variables are used in examples. Replace them with your actual environment values.

VariableExampleDescription
<<USERNAME>>exampleuserYour local login username
<<SERVER>>192.168.1.10Target host or IP address
<<USER>>ubuntu or ec2-userSSH username on the server
<<EMAIL_ADDRESS>>user@example.comOptional comment for key identification

Note for Windows Users
The Windows commands in this article assume PowerShell.
If using Command Prompt, replace $env:USERPROFILE with %USERPROFILE%.

Open PowerShell as Administrator and run:

Terminal window
ssh-keygen -t ed25519 -C "<<EMAIL_ADDRESS>>"

Example output:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/C:/Users/<<USERNAME>>/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
  • Public Key: $env:USERPROFILE\.ssh\id_ed25519.pub
  • Private Key: $env:USERPROFILE\.ssh\id_ed25519
Terminal window
cat $env:USERPROFILE\.ssh\id_ed25519.pub | ssh <<USER>>@<<SERVER>> "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"

Alternatively, manually paste the content of .pub into the server’s ~/.ssh/authorized_keys.

Terminal window
ssh -i $env:USERPROFILE\.ssh\id_ed25519 <<USER>>@<<SERVER>>

Terminal window
ssh-keygen -t ed25519 -C "<<EMAIL_ADDRESS>>"
  • Public Key: ~/.ssh/id_ed25519.pub
  • Private Key: ~/.ssh/id_ed25519

Use ssh-copy-id for automated setup:

Terminal window
ssh-copy-id -i ~/.ssh/id_ed25519.pub <<USER>>@<<SERVER>>

Or manually append the public key to ~/.ssh/authorized_keys.

Terminal window
ssh -i ~/.ssh/id_ed25519 <<USER>>@<<SERVER>>

If you generated a key with a passphrase, configure an SSH agent to avoid entering it every time.
The agent securely stores private keys in memory and automatically signs authentication requests.

Windows:

Terminal window
Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent

Linux:

Terminal window
eval "$(ssh-agent -s)"

Windows:

Terminal window
Set-Service -Name ssh-agent -StartupType Automatic

Linux: Add the following to ~/.bashrc or ~/.profile:

Terminal window
eval "$(ssh-agent -s)" > /dev/null

Windows:

Terminal window
ssh-add $env:USERPROFILE\.ssh\id_ed25519

Linux:

Terminal window
ssh-add ~/.ssh/id_ed25519
Terminal window
ssh-add -l

You should see the fingerprint of your registered key.


Avoid repetitive command typing by creating an SSH config file.

Path:

  • Linux: ~/.ssh/config
  • Windows: C:\Users\<<USERNAME>>\.ssh\config
Host myserver
HostName <<SERVER>>
User <<USER>>
IdentityFile ~/.ssh/id_ed25519
Port 22

Then simply connect using:

Terminal window
ssh myserver

For multiple servers:

Host web
HostName 192.168.1.10
User ubuntu
IdentityFile ~/.ssh/id_ed25519
Host db
HostName 192.168.1.11
User ec2-user
IdentityFile ~/.ssh/id_ed25519

Tip: Use separate key pairs per host for higher security.


To verify or troubleshoot connections:

Terminal window
ssh -vvv -i ~/.ssh/id_ed25519 <<USER>>@<<SERVER>>

Look for:

debug1: Authentication succeeded (publickey)

Common failure causes:

  1. Server doesn’t allow public key authentication
    → Check PubkeyAuthentication yes in /etc/ssh/sshd_config.

  2. Incorrect or missing authorized_keys entry
    → Ensure key is properly copied to the correct user’s .ssh directory.

  3. Wrong username or host
    → Verify connection parameters and permissions.


SSH public key authentication enables secure, passwordless server access.
Both Windows and Linux support easy setup via ssh-keygen.
Proper key management and permissions are essential for a reliable configuration.