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-keygen

Make a key pair

Syntaxssh-keygen [options]
  • ssh-keygen -t ed25519 -C "[email protected]"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 [email protected] "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

#sftp

Interactive transfer

Syntaxsftp user@host
  • sftp [email protected]CMD

    Open a session

  • put local.txtCMD

    Upload (inside sftp)

  • get remote.txtCMD

    Download (inside sftp)

#ssh tunnels

Forward ports

Syntaxssh -L / -R / -D

#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