PowerShell SSH: Connect to Linux Servers from Windows

PowerShell SSH: Connect to Linux Servers from Windows

PowerShell Tips Editor 4 min read
PowerShell SSH: Connect to Linux Servers from Windows

You no longer need PuTTY to SSH from Windows — Windows 10 (version 1809 and later) ships with a real OpenSSH client built right in. PowerShell SSH works from any terminal, supports key-based authentication, remote command execution, and SCP file transfers, all without installing anything extra. If you manage Linux servers or network devices from a Windows machine, this guide walks you through every step from enabling the client to configuring an SSH config file for saved hosts.

Enable OpenSSH Client on Windows

On Windows 10/11, the OpenSSH client is an optional feature. Check whether it is already installed, and if not, install it from PowerShell with admin rights.

# Check if OpenSSH client is installed
Get-WindowsCapability -Online -Name OpenSSH.Client*
Name  : OpenSSH.Client~~~~0.0.1.0
State : Installed
# Install it if State shows NotPresent
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

After installation, ssh.exe is available in your PATH and works directly from any PowerShell session.

Connect with Password Authentication

Connect to a Linux server using a username and password. The syntax is identical to OpenSSH on Linux/macOS. You will be prompted for the password interactively.

# Basic SSH connection
ssh [email protected]

# Specify a non-default port
ssh -p 2222 [email protected]

# Connect with verbose output for troubleshooting
ssh -v [email protected]

The first time you connect to a new host, SSH will ask you to confirm the host fingerprint — type yes to add it to your known_hosts file.

Set Up SSH Key Authentication

Key-based authentication is more secure than passwords and enables non-interactive connections, which is essential for PowerShell automation. Generate a key pair on your Windows machine and copy the public key to the Linux server.

# Generate an Ed25519 key pair (recommended)
ssh-keygen -t ed25519 -C "[email protected]"
# Keys saved to: C:\Users\YourName\.ssh\id_ed25519 and id_ed25519.pub

# Copy public key to remote server (Linux must have ssh-copy-id or do it manually)
# On the remote server, append your public key to: ~/.ssh/authorized_keys
$pubKey = Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub"
ssh [email protected] "mkdir -p ~/.ssh && echo '$pubKey' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Once the public key is on the server, SSH connects without prompting for a password.

Run a Command Over SSH

Pass a command as the final argument to ssh to execute it non-interactively and return the output to your local PowerShell session. This is the core of scripted automation against Linux targets.

# Run a single command
ssh [email protected] "df -h"

# Run multiple commands
ssh [email protected] "uptime; free -m; df -h"

# Capture output in a variable
$diskInfo = ssh [email protected] "df -h /var"
Write-Output $diskInfo
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        50G   18G   30G  38% /var

Copy Files with SCP

scp (secure copy) is included with the OpenSSH client. Use it to transfer files to and from Linux servers without setting up FTP or SMB shares. The syntax mirrors standard file copy with a remote path prefix.

# Copy a file TO the remote server
scp "C:\Logs\report.csv" [email protected]:/home/username/reports/

# Copy a file FROM the remote server
scp [email protected]:/var/log/syslog "C:\Logs\syslog.txt"

# Copy an entire directory recursively
scp -r "C:\Scripts\deploy" [email protected]:/opt/scripts/

SSH Config File for Saved Hosts

Rather than typing the full hostname and username every time, define named SSH hosts in ~\.ssh\config. PowerShell can create and manage this file directly.

# Create or append SSH config
$configEntry = @"
Host webserver
    HostName 192.168.1.100
    User ubuntu
    IdentityFile ~/.ssh/id_ed25519
    Port 22

Host dbserver
    HostName 192.168.1.200
    User admin
    IdentityFile ~/.ssh/id_ed25519
"@

$configPath = "$env:USERPROFILE\.ssh\config"
Add-Content -Path $configPath -Value $configEntry

With this config in place, you connect with just ssh webserver — no IP address or username needed.

Common Errors and Fixes

  • OpenSSH feature not enabled: If ssh is not found, it is not installed. Run Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 with admin rights. On Windows Server, check under Settings > Optional Features or use the DISM command. Do not confuse the SSH client with the SSH server — you only need the client to connect outbound.
  • Key permissions too open: On Windows, SSH private keys must have restricted permissions. If the private key file is readable by other accounts, SSH will refuse to use it with an “Unprotected private key file” error. Fix it by running: icacls "$env:USERPROFILE\.ssh\id_ed25519" /inheritance:r /grant:r "${env:USERNAME}:R". This sets the file to read-only for your account only.

Related Cmdlets / See Also

Wrapping Up

Windows OpenSSH gives you a first-class SSH experience without any third-party software — key auth, SCP, and saved host configs all work natively. Set up an SSH config file with your most-used servers as an immediate next step so you can connect with a single short alias from any PowerShell window.

Send-Item -To