Copying an SSH Key from Windows to a Debian Server
Step-by-step guide to setting up passwordless SSH from a Windows workstation to a Debian-based server. Covers the quick ssh-copy-id method (via Git Bash), the explicit manual method, troubleshooting permission issues, hardening with password-auth disabled, and per-host SSH config aliases.
Once key-based SSH authentication is in place you'll never type a password for that machine again. This guide covers copying an existing SSH public key from a Windows workstation to a Debian-based server - the quick way and the manual way - plus hardening steps to lock it down afterwards.
🔍Sanity Checks (Do This First)
Before anything else, confirm you actually have an SSH keypair on the Windows side.
- 1Check for an existing keypair
Open PowerShell and list the
.sshdirectory:shelldir $env:USERPROFILE\.sshYou should see one of:
id_ed25519+id_ed25519.pub— preferred (modern, fast, compact)id_rsa+id_rsa.pub— older but still widely supported
- 2Generate a keypair if you don't have one
If no keypair exists, generate one now. Accept the default file location and optionally set a passphrase:
bashssh-keygen -t ed25519 -C "your-name@windows"ℹ️Ed25519 keys are shorter, faster, and more secure than RSA. Use them unless you have a specific compatibility reason not to.
🚀Method A - ssh-copy-id (Recommended)
The ssh-copy-id command reads your public key, connects to the server, creates the correct directories and files with the right permissions, and appends the key — all in a single step.
ssh-copy-id command is not available in PowerShell by default. Run it from a Bash-compatible terminal on Windows such as Git Bash, which ships with Git for Windows.- 1Copy the public key to the server
From a Bash terminal (e.g. Git Bash), run:
bashssh-copy-id <user>@<server-ip>Enter the remote user's password when prompted. This is the last time you'll need it.
- 2Test passwordless loginbash
ssh <user>@<server-ip>If you land on the remote shell without a password prompt — you're done. Skip ahead to the Hardening section.
🔧Method B - Manual Install (Explicit & Bullet-Proof)
Use this if ssh-copy-id is unavailable or you want full control and understanding of what's happening under the hood.
- 1Copy the public key contents on Windows
In PowerShell, print the key:
shelltype $env:USERPROFILE\.ssh\id_ed25519.pubYou'll see a single line like:
textssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... your-name@windowsCopy the entire line to your clipboard.
- 2SSH into the server (password login, one last time)bash
ssh <user>@<server-ip> - 3Create the SSH directory with correct permissions
On the remote server, run:
bashmkdir -p ~/.ssh chmod 700 ~/.ssh touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys⚠️These permissions are critical. SSH will silently refuse key authentication if the directory or file permissions are too open. - 4Paste the public key
Open the authorized keys file in an editor:
bashnano ~/.ssh/authorized_keys- Paste the public key on a single line
- Save and exit (
Ctrl+O,Enter,Ctrl+X)
- 5Fix ownership
Ensure the
.sshdirectory is owned by the correct user:bashchown -R <user>:<user> ~/.ssh - 6Test from Windowsbash
ssh <user>@<server-ip>No password prompt = success.
🐛Troubleshooting
Still being asked for a password? Work through these common failure points:
Check SSH Server Config
On the Debian server, open the SSH daemon configuration:
sudo nano /etc/ssh/sshd_configEnsure the following lines are present and not commented out:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keysThen restart the SSH service:
sudo systemctl restart sshVerify Permissions (Most Common Mistake)
Incorrect permissions are the number-one reason key auth silently fails:
ls -ld ~ ~/.ssh ~/.ssh/authorized_keysExpected output:
drwx------ <user> <user> /home/<user>/.ssh
-rw------- <user> <user> /home/<user>/.ssh/authorized_keyschmod 755 ~ or stricter is fine.🔒Hardening (Strongly Recommended)
Once you've confirmed key-based login works, disable password authentication to close off brute-force attack vectors entirely.
- 1Edit the SSH daemon configbash
sudo nano /etc/ssh/sshd_config - 2Set the following directivestext
PasswordAuthentication no PermitRootLogin no - 3Restart the SSH servicebash
sudo systemctl restart sshFrom this point on, only machines whose public keys are in
authorized_keyscan connect.
⚡Optional: Per-Host SSH Config on Windows
Save yourself from typing full connection strings every time by defining a host alias in your local SSH config.
- 1Open (or create) the SSH config fileshell
notepad $env:USERPROFILE\.ssh\config - 2Add a host blocktext
Host myserver HostName <server-ip> User <user> IdentityFile ~/.ssh/id_ed25519 - 3Connect using the aliasbash
ssh myserverClean. Elegant. No more remembering IPs or usernames.
📋Quick Reference
Fastest path (from Git Bash on Windows):
# Copy key to server (one-time)
ssh-copy-id <user>@<server-ip>
# Connect — no password needed
ssh <user>@<server-ip>ssh-copy-id from Git Bash for the fastest setup, or install the key manually for full control. Then disable password authentication on the server and optionally set up a host alias for effortless connections.Filed under: SSH, Security, Windows, Debian, Linux, Key Authentication, Infrastructure, Home Lab