← Back to blog

PowerShell SSH: How to Connect to a Server on Windows

··
Windows PowerShell SSH command-line tutorial with OpenSSH connection examples

You can connect to a Linux server directly from Windows PowerShell using the built-in OpenSSH client. No PuTTY, additional PowerShell module, or local SSH server is required for an ordinary outbound connection.

Start by checking ssh -V, connect with ssh username@host, then use an SSH key, custom port, or saved host configuration if needed. This guide covers Windows 10/11 and separates ordinary OpenSSH from PowerShell Remoting over SSH.

Quick answer · PowerShell on Windows

Replace the username and hostname with a real account and server. The hostname above is documentation-only. On the first login, independently verify the server fingerprint before accepting the host key. You may then be prompted for a password, key passphrase, or another configured authentication method.

If you prefer a graphical Windows SSH client after learning the commands, see our Windows SSH client comparison. PowerShell itself is enough for everyday command-line access.

PowerShell SSH commands at a glance

TaskCommand
Check OpenSSH clientssh -V
Connect to Linux serverssh user@host
Non-default portssh -p 2222 user@host
Use a private keyssh -i "$HOME\.ssh\id_ed25519" user@host
Test an SSH portTest-NetConnection host -Port 22
Show client config, no networkssh -G myserver
Debug an SSH attemptssh -v user@host

Normal ssh works in Windows PowerShell 5.1 as well as PowerShell 7 when OpenSSH is installed. Enter-PSSession -HostName is a separate feature with extra prerequisites.

Step 1: Check whether SSH is installed

Open Windows Terminal or PowerShell. You do not need an elevated terminal to connect to a remote server.

Get-Command ssh ssh -V

A successful check reports the ssh.exe command and an OpenSSH version. On Windows the executable is commonly located at C:\Windows\System32\OpenSSH\ssh.exe. If it is already available, skip installation.

PowerShell shows the ssh command path and installed OpenSSH version
OpenSSH client is available in PowerShell: Get-Command ssh resolves the client and ssh -V confirms the installed version.

Install OpenSSH Client only if it is missing

From an Administrator PowerShell window, check the optional Windows feature and install only the client if necessary:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*' Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

Open a new PowerShell tab and run ssh -V again. You can also install OpenSSH Client through Windows Optional Features. The OpenSSH Server feature and the sshd Windows service are unnecessary when you only want to connect out to another machine. See setting up the Windows SSH server only if other computers need to connect to your Windows PC.

Microsoft documents these steps in its OpenSSH installation guide.

Step 2: Connect to a server from PowerShell

You need a reachable SSH server, its username, and either a valid password or an authorized SSH key. Use the remote Linux account name, not necessarily your Windows username:

ssh [email protected] # Or, for a real server IP: ssh [email protected]

The addresses above are examples, not live servers. If no username is specified, SSH may try your local account name. An initial host-key prompt asks you to verify the remote server identity. Compare the SHA256 fingerprint with a trusted provider console or administrator before answering yes.

Verify the first-login host key

The authenticity of host 'server.example.com' can't be established. ED25519 key fingerprint is SHA256:... Are you sure you want to continue connecting (yes/no/[fingerprint])?

After a verified first connection, OpenSSH records the host key in ~/.ssh/known_hosts. A later key-change warning deserves investigation, not an automatic StrictHostKeyChecking=no workaround. Read how to handle a changed host key.

Successful SSH connection from Windows PowerShell with a whoami check
A real PowerShell SSH session to the server. The connection succeeds and the whoami check confirms that the remote shell is active.

Step 3: Connect on a custom SSH port

SSH normally uses TCP port 22. For a server listening on 2222, use the lowercase -p flag:

ssh -p 2222 [email protected]

The server must actually listen on that port, and any cloud firewall or security group must allow access. To test basic TCP reachability before attempting authentication:

Test-NetConnection server.example.com -Port 2222

TcpTestSucceeded : True only confirms TCP reachability. It does not verify SSH credentials or host-key identity. For deeper diagnostics use ssh -v -p 2222 [email protected].

Step 4: Connect using an SSH private key

When a server has your public key registered in its ~/.ssh/authorized_keys, you can authenticate with the corresponding private key. Specify it with -i:

$key = Join-Path $HOME ".ssh\id_ed25519" ssh -i "$key" [email protected]

If you do not have a key pair yet, generate one with a unique filename so an existing default key is not overwritten:

New-Item -ItemType Directory -Force -Path "$HOME\.ssh" | Out-Null ssh-keygen -t ed25519 -f "$HOME\.ssh\id_ed25519_powershell"

Provide the public key (the .pub file) to your server administrator or append it safely to the appropriate account’s authorized_keys. Never upload the private key and do not overwrite an existing authorized_keys file using a blind SCP copy. Keep the private-key passphrase if one was set.

For a dedicated setup, see generate SSH keys, connect with a private key, and fix public-key authentication.

Step 5: Save a server in Windows SSH config

Instead of repeating the username, port, hostname and key path, create a host alias in the OpenSSH client config file. Windows normally uses %USERPROFILE%\.ssh\config (the filename is exactly config, without .txt):

$sshDir = Join-Path $HOME '.ssh' New-Item -ItemType Directory -Force -Path $sshDir | Out-Null $config = Join-Path $sshDir 'config' if (-not (Test-Path $config)) { New-Item -ItemType File -Path $config | Out-Null } notepad $config

Add this to the file, replacing the demonstration hostname, username and key with your own:

Host my-vps HostName server.example.com User deploy Port 2222 IdentityFile ~/.ssh/id_ed25519

Save, then verify how the alias resolves without making a network connection:

ssh -G my-vps | Select-String -Pattern '^(hostname|user|port|identityfile) ' ssh my-vps

The final ssh my-vps line does connect and should be used only after you replace the example values. Read the larger SSH config examples guide for multiple hosts, ProxyJump and patterns.

Run remote Linux commands from PowerShell

A command after the destination runs on the remote host and sends its output back to PowerShell. This does not create a PowerShell Remoting session:

ssh [email protected] 'uptime' ssh [email protected] 'whoami' ssh [email protected] 'echo $HOME'

PowerShell expands variables inside local double-quoted strings. A single-quoted local argument can be useful when the remote Linux shell, rather than your Windows PowerShell, should expand a variable such as $HOME. More complex nested quotes need additional care because PowerShell parses arguments before passing them to native executables.

For pipelines and more complex commands, consult running SSH remote commands and Microsoft’s PowerShell quoting rules.

Transfer files with SCP or SFTP in PowerShell

Once OpenSSH is installed, scp and sftp are typically available alongside ssh on Windows. For example:

scp .\report.txt [email protected]:/tmp/report.txt sftp [email protected]

Both tools can use the same SSH keys and Host aliases. When specifying a port directly, scp uses uppercase -P, unlike ssh -p. A saved host alias avoids remembering the difference.

For more examples, see SCP file transfers and the SSH config guide.

PowerShell SSH vs PowerShell Remoting over SSH

ssh user@host and Enter-PSSession -HostName ... are different features. Ordinary SSH gives you the destination system’s shell (for example Bash on Linux). PowerShell Remoting uses SSH as a transport to launch a PowerShell subsystem on the remote system.

FeatureCommandNeeds
OpenSSH client from PowerShellssh user@hostOpenSSH client on Windows, SSH server on destination
PowerShell Remoting over SSHEnter-PSSession -HostName host -UserName userPowerShell 6+ and SSH, plus remote PowerShell subsystem configuration
Enter-PSSession -HostName server.example.com -UserName deploy

That command is not a drop-in replacement for logging into any Linux SSH server. The remote host must have PowerShell installed and expose the appropriate Subsystem powershell ... configuration in sshd_config. For exact setup and supported caveats, use Microsoft Learn’s PowerShell remoting over SSH guide.

Fix common PowerShell SSH errors

Error or symptomLikely cause / check
ssh is not recognizedOpenSSH Client not installed or not on PATH; test with Get-Command ssh
Could not resolve hostnameDNS, typo, invalid alias or wrong config file
Connection refusedNo accepting SSH listener at the specified address/port
Connection timed outFirewall, routing or address issue; test with Test-NetConnection
Permission denied (publickey)Wrong user, private key, public-key authorization or server policy
REMOTE HOST IDENTIFICATION HAS CHANGEDStored server host key differs; verify cause before altering known_hosts
Bad permissions on a keyWindows file ACL allows excessive access; inspect key permissions rather than weakening security checks

Diagnose from Windows with the following read-only checks:

Get-Command ssh Test-NetConnection server.example.com -Port 22 ssh -v [email protected]

The last command attempts a real connection. Do not post full verbose logs publicly without checking them for usernames, addresses or sensitive environment details. Read connection refused, connection timeout and public-key failure for targeted fixes.

PowerShell SSH quick-reference table

Use caseCommand
Show SSH versionssh -V
Basic connectionssh user@host
Use custom portssh -p 2222 user@host
Use a specific keyssh -i "$HOME\.ssh\id_ed25519" user@host
Use a host aliasssh my-vps
Inspect host aliasssh -G my-vps
Run a commandssh user@host 'uptime'
Copy a local filescp .\report.txt user@host:/tmp/
Interactive file transfersftp user@host
Test TCP portTest-NetConnection host -Port 22
Verbose connectionssh -v user@host

PowerShell SSH FAQ

Can I use SSH in Windows PowerShell 5.1?

Yes, when the OpenSSH client is installed. PowerShell 7 is not required for the normal ssh command. PowerShell Remoting over SSH is a separate feature.

Do I need PuTTY or Posh-SSH?

No. Standard SSH connections work using Windows OpenSSH without an additional PowerShell module. Third-party clients may offer convenience features, but they are optional.

Do I need to install OpenSSH Server on my Windows PC?

Not to connect out to a Linux server. Install the OpenSSH Client locally; the destination must run an SSH server.

Where is the SSH config file on Windows?

The per-user file is normally %USERPROFILE%\.ssh\config, without a file extension. PowerShell can open it via notepad (Join-Path $HOME ".ssh\config").

Why can I reach port 22 but still get Permission denied?

A successful TCP test checks reachability, not SSH authentication. Verify the exact remote username and the configured password or public key.

Can I SSH into Windows from another PC?

Yes, if the destination Windows machine has OpenSSH Server installed, listening and allowed through its firewall. That is different from using PowerShell as the client.

Official references and further reading

For client installation follow Microsoft’s Windows OpenSSH instructions. For structured remote PowerShell sessions refer to Microsoft PowerShell Remoting over SSH. PowerShell native-command quoting is covered in about_Quoting_Rules.

Further ShadeTerm guides: Windows SSH Server, SSH config examples, SSH with a private key, and SSH command usage.

Conclusion: connect securely from PowerShell

Windows PowerShell can run the regular OpenSSH client with the same core commands as Linux and macOS. Start with ssh -V, confirm the host fingerprint, and connect with ssh user@host. Add a private key, custom port and ~/.ssh/config alias only as you need them. For GUI workflows involving terminals and SFTP, ShadeTerm for Windows can complement the command line without changing how SSH authentication works.

PowerShell SSH or a GUI client?

PowerShell and OpenSSH are free and often all you need for shell access. When you need terminal tabs, graphical SFTP, a remote editor and server monitoring in one Windows workspace, you can try ShadeTerm. For a neutral overview of free and paid tools, see our Windows SSH client comparison.