SSH Key Authentication to Raspberry Pi from Windows
This guide demonstrates how to securely connect to a Raspberry Pi using SSH key authentication from a Windows environment. While traditional password authentication works, SSH keys provide a more secure and convenient method for remote access.
Prerequisites:
- Windows 10 or 11 with PowerShell
- Raspberry Pi with SSH enabled
- Network connectivity between Windows machine and Raspberry Pi
- Basic command line knowledge
Note: This tutorial uses PowerShell as the primary tool. Visual Studio Code is mentioned as an optional enhancement but is not required for SSH connectivity.
Understanding SSH Key Authentication
SSH key authentication uses a cryptographic key pair instead of passwords:
- Private key: Stays on your Windows machine (never share this!)
- Public key: Gets copied to the Raspberry Pi
This method is more secure than passwords and eliminates the need to type credentials repeatedly.
Generating SSH Key Pair
Open PowerShell
Press Win + X and select "Windows PowerShell" or search for "PowerShell" in the Start menu.
Generate the key pair
Run the following command to create a modern, secure key pair:
ssh-keygen -t ed25519 -C "your-email@example.com"Why Ed25519? It's more secure and performant than the older RSA algorithm. If you need RSA for compatibility reasons, use:
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"Configure your key
During generation, you'll be prompted for:
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\YourName\.ssh\id_ed25519): rpi_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:Important decisions:
- Filename: Use a descriptive name like
rpi_keyto identify this key's purpose - Passphrase: Strongly recommended for security. You'll enter this when using the key. I left it blank for now.
- Location: Keys are saved in
C:\Users\%USERNAME%\.ssh\by default
After completion, you'll have two files:
rpi_key(private key - guard this carefully!)rpi_key.pub(public key - safe to share)
Configuring the Raspberry Pi
Initial connection
First, connect to your Raspberry Pi using password authentication:
ssh pi@192.168.1.100 # Replace with your Pi's IP addressTransfer the public key
From your Windows PowerShell, run:
type $env:USERPROFILE\.ssh\rpi_key.pub | ssh pi@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"This command:
- Reads your public key file
- Creates the
.sshdirectory on the Pi if it doesn't exist - Appends the key to the
authorized_keysfile
Set correct permissions
Still connected to your Pi, ensure proper permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysThese permissions are crucial - SSH will refuse keys if permissions are too open.
Testing Key-Based Authentication
Test the connection
From PowerShell, connect using your new key:
ssh -i $env:USERPROFILE\.ssh\rpi_key pi@192.168.1.100
```
If you set a passphrase, you'll be prompted for it. Otherwise, you should connect directly without a password prompt.Create an SSH config file (Optional but recommended)
This simplifies future connections. Create or edit C:\Users\%USERNAME%\.ssh\config:
Host rpi
HostName 192.168.1.100 # Your Pi's IP or hostname
User pi # Your Pi username
IdentityFile ~/.ssh/rpi_key
Port 22Now you can connect simply with:
ssh rpiOptional: Visual Studio Code Integration
VSCode offers a excellent GUI for SSH connections and remote development.
Install Remote-SSH extension
- Open VSCode
- Go to Extensions (Ctrl+Shift+X)
- Search for "Remote - SSH" by Microsoft
- Install the extension

Configure connection
- Press
Ctrl+Shift+Pto open command palette - Type "Remote-SSH: Open Configuration File"
- Select
C:\Users\%USERNAME%\.ssh\config - Add your Pi configuration (if not already done in step 4.2)
Connect through VSCode
- Click the Remote Explorer icon in the sidebar
- Find your "rpi" host
- Click the connection icon
- VSCode will open a new window connected to your Pi
Benefits of VSCode:
- Full IDE features on remote files
- Integrated terminal
- File explorer for the Pi
- Extension support on remote host
Enhancing Security
Once your basic SSH key authentication is working, consider exploring these security enhancements:
SSH Hardening
- Disable password authentication in
/etc/ssh/sshd_config - Change default SSH port from 22
- Implement fail2ban for brute-force protection
Key Management
- Use ssh-agent for passphrase caching
- Consider hardware security keys (FIDO2/U2F)
- Use different keys for different environments (dev/prod)
Network Security
- Configure firewall rules (ufw/iptables)
Conclusion
You've successfully configured SSH key authentication between Windows and your Raspberry Pi. This setup provides:
- Enhanced security over password authentication
- Convenience of passwordless login (with ssh-agent)
- Integration with development tools like VSCode
This foundation enables secure remote development, file transfers, and system administration. Whether you're building IoT projects, learning Linux, or running home automation, secure SSH access is an essential skill.
Additional Resources
- Official Raspberry Pi SSH Documentation
- OpenSSH Documentation
- VSCode Remote Development
- SSH Key Management Best Practices
Remember: Security is a journey, not a destination. Keep learning and stay updated with best practices!
See you soon !
Yacine