SSH Command in Windows with examples

SSH and file transfer commands in Windows

Windows 10 and 11 include the OpenSSH client, so these commands work in CMD and PowerShell, just like on Linux.

#ssh

Log in to a server

Syntaxssh [options] user@host
  • ssh deploy@203.0.113.10CMD

    Log in as deploy

  • ssh -p 2222 deploy@example.comCMD

    Different port

  • ssh -i %USERPROFILE%\.ssh\id_ed25519 deploy@example.comCMD

    Use a specific key

  • ssh deploy@example.com "df -h"CMD

    Run one command and come back

  • ssh -J jump@bastion.example.com deploy@10.0.0.5CMD

    Through a jump host

TipIf ssh is not found, open Settings, Apps, Optional features, and add OpenSSH Client.

#ssh-keygen

Make a key pair

Syntaxssh-keygen [options]
  • ssh-keygen -t ed25519 -C "me@example.com"CMD

    Create a key; it is saved in C:\Users\you\.ssh

  • ssh-keygen -lf %USERPROFILE%\.ssh\id_ed25519.pubCMD

    Show the fingerprint

#Install the key on a server

There is no ssh-copy-id on Windows

SyntaxPowerShell
  • type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@example.com "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"PowerShell

    Add your public key to the server

#ssh-agent

Remember passphrases

Syntaxssh-add [key]
  • Get-Service ssh-agent | Set-Service -StartupType AutomaticPowerShell

    Allow the agent to start (administrator)

  • Start-Service ssh-agentPowerShell

    Start it

  • ssh-add %USERPROFILE%\.ssh\id_ed25519CMD

    Unlock the key once

#scp

Copy files over SSH

Syntaxscp source destination
  • scp report.pdf deploy@example.com:/home/deploy/CMD

    Upload

  • scp deploy@example.com:/var/log/app.log .CMD

    Download

  • scp -r site deploy@example.com:/var/www/CMD

    A whole folder

  • scp C:\Data\file.zip deploy@example.com:~CMD

    Windows path as the source

#sftp

Interactive transfer

Syntaxsftp user@host
  • sftp deploy@example.comCMD

    Open a session

  • put local.txtCMD

    Upload (inside sftp)

  • get remote.txtCMD

    Download (inside sftp)

#ssh tunnels

Forward ports

Syntaxssh -L / -R / -D
  • ssh -L 5432:127.0.0.1:5432 deploy@example.comCMD

    Reach the server's database at localhost:5432

  • ssh -D 1080 deploy@example.comCMD

    A SOCKS proxy at localhost:1080

#config file

Shortcuts for servers

SyntaxC:\Users\you\.ssh\config
  • Host webCMD

    A line in the config file

  • HostName 203.0.113.10CMD

    Add the address on the next line

  • User deployCMD

    and the user; now just type: ssh web

#Get-WindowsCapability

Install OpenSSH

SyntaxAdd-WindowsCapability
  • Get-WindowsCapability -Online | Where Name -like 'OpenSSH*'PowerShell

    See if it is installed

  • Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0PowerShell

    Install the client (administrator)

  • Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0PowerShell

    Install the server, if you want to log in to this PC

#sshd

Run an SSH server on Windows

SyntaxStart-Service sshd
  • Start-Service sshdPowerShell

    Start the server

  • Set-Service -Name sshd -StartupType AutomaticPowerShell

    Start it at every boot

TipAllow port 22 in the firewall, then connect with SSH Command from another computer.

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Linux commands with examples SFTP & FTP client