This guide describes how to set up SSH key-based authentication to a Raspberry Pi using Windows PowerShell.
1. Generate an SSH Key Pair
Open Windows PowerShell and run:
ssh-keygen -t ed25519 -C "your_email@example.com"
Press Enter to accept the default path (C:\Users\YourName.ssh\id_ed25519).
Optionally enter a passphrase for extra security.
Display the public key to copy it:
type $env:USERPROFILE\.ssh\id_ed25519.pub
Copy the entire output line. It should start with ssh-ed25519.
2. Login to Linux Host normally
Create the .ssh Directory on the Pi
mkdir -p ~/.ssh
chmod 700 ~/.ssh
3. Create or edit authorized_keys File
Open the file
nano ~/.ssh/authorized_keys
In the editor, paste the entire public key
4. Set correct permissions
chmod 600 ~/.ssh/authorized_keys
Confirm configuration:
sudo nano /etc/ssh/sshd_config
Ensure the following lines are set:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes
sudo systemctl restart ssh
5. Test SSH Key Authentication
ssh username@<ip_address>
It should connect without a password prompt
6. (Optional) Disable Password Authentication
After confirming key-based login works, you can improve security by disabling password login:
sudo nano /etc/ssh/sshd_config
set:
PasswordAuthentication no
Restart SSH
sudo systemctl restart ssh
Notes
If key authentication fails, test with verbose output:
ssh -vvv username@<ip_address>
Ensure correct permissions on the Pi:
~/.ssh directory: 700
~/.ssh/authorized_keys: 600
Do not delete your private key (id_ed25519) on your Windows machine.