SSH (Secure Shell) provides secure, encrypted remote access between systems. This guide explains how to connect from a Windows client to a Linux or Windows server using OpenSSH.
Prerequisites
Windows 10 (version 1809 and later) and Windows 11 include the OpenSSH client by default. Most Linux distributions also come with the OpenSSH client pre-installed. The client machine requires an SSH client, while the server machine must have an SSH server installed and running.
Step 1: Check SSH Installation
Client Machine:
ssh -V
If SSH is missing, install the OpenSSH client.
Server Machine:
- Linux:
sudo systemctl status sshd
- Windows:
Get-Service sshd
Step 2: Connect via SSH
Basic connection:
ssh username@target_ip_address
Enter the password when prompted.
Connect using a specific port:
ssh -p <port> username@target_ip_address
Verbose output for troubleshooting:
ssh -v username@target_ip_address
Step 3: Use SSH Key Authentication
Instead of passwords, you can authenticate with a private key.
Generate SSH key pair on the client machine:
ssh-keygen -t rsa -b 4096
Keys are stored in:
- Private key:
C:\Users\YourUser\.ssh\id_rsa(keep secret) - Public key:
C:\Users\YourUser\.ssh\id_rsa.pub(copy to server)
Copy Public Key to Linux Server
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@target_ip_address "cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
If .ssh does not exist:
ssh username@target_ip_address "mkdir -p ~/.ssh && chmod 700 ~/.ssh"
Copy Public Key to Windows Server
Client Machine:
Get-Content $env:USERPROFILE\.ssh\id_rsa.pub
Server Machine:
mkdir "C:\Users\YourUser\.ssh" New-Item -Path "C:\Users\YourUser\.ssh\authorized_keys" -ItemType File notepad "C:\Users\YourUser\.ssh\authorized_keys"
Paste the public key into authorized_keys and save.
System-Wide SSH Keys (Windows)
Move authorized_keys to C:\ProgramData\ssh and rename it:
administrators_authorized_keys
Step 4: Configure SSH for Quick Access
Edit the SSH config file:
notepad $env:USERPROFILE\.ssh\config
Add configuration:
Host myserver
HostName target_ip_address
User username
Port <port>
IdentityFile C:\Users\YourUser\.ssh\id_rsa
Save the file as config (no extension) and select “All Files” in the save dialog.
Step 5: Connect Using SSH Key
Using alias:
ssh myserver
Specifying identity file:
ssh -i C:\Users\YourUser\.ssh\id_rsa username@target_ip_address
Note:
If your machine uses DHCP, the IP may change. To avoid reconnect issues:
- Configure a DHCP reservation in your router.
- Or assign a static IP to the machine.
You can use the local IP address of the device if both devices are on the same local network. If the device is outside the local network, you need to use the public IP address.
Replace username, target_ip_address, and YourUser with your actual details. You can customize myserver with any alias you prefer.
By following these steps, you can establish secure SSH connections from Windows to Linux or Windows servers, using either password or key-based authentication.
With SSH properly configured, you’ll enjoy secure, streamlined remote access for administration, development, and file transfers.
