Complete Guide to Using SSH from PowerShell: Configuration and Practical Examples

Last update: 07/05/2025
Author Isaac
  • PowerShell allows you to connect and manage remote systems using SSH natively in Windows 10/11 and recent versions.
  • Installing and configuring OpenSSH as a client and server is simple, allowing for password or public key authentication based on security needs.
  • PowerShell SSH's advanced features include automation, session management, and customization, making remote administration in mixed environments easy.

SSH connection from PowerShell

Connecting via SSH directly from PowerShell is no longer the domain of administration gurus. Today, any Windows user can access and manage servers, and even automate tasks through an SSH terminal , thanks to the native integrations in Windows 10 and later versions. The process is not only easier than ever, but it has also been refined in terms of stability and security, making it a robust alternative to traditional external clients.

If you've ever needed to manage a remote system, copy files, review logs , or run commands on a Linux or Windows server without leaving your desk, this detailed guide will be invaluable. You'll learn everything from OpenSSH requirements, installation, and configuration on different platforms to practical examples using both basic commands and advanced PowerShell SSH features to get the most out of remote administration.

What is SSH and why use it from PowerShell?

SSH (Secure Shell) is a secure communication protocol that allows access to and management of remote systems through a terminal . Its main advantage over other protocols like Telnet is end-to-end encryption, which ensures that all information, including usernames and passwords, is fully protected during transmission.

PowerShell, for its part, is Windows' advanced command-line interface , used for both user and administrative tasks. For several years now, Windows has integrated a native SSH client, allowing users to harness the full power of SSH directly from PowerShell, facilitating the simple and secure administration of Linux, Windows, and other remote devices.

Prerequisites for using SSH from PowerShell

SSH PowerShell Requirements

Before you start managing remote systems from PowerShell, you need to check some basic requirements on your computer and the target computer:

  • PowerShell updated: It is recommended to use PowerShell 6 or later to take advantage of all features. It comes preinstalled on Windows 10 and 11, but it's a good idea to check the version with the command $PSVersionTable.PSVersion.
  • OpenSSH Client: You need the OpenSSH client installed. Starting with Windows 10 (build 1809) and Windows Server 2019, it's included as an optional feature, although you can install it manually if necessary.
  • SSH server enabled on the remote computer: The system you will connect to must have SSH enabled (this can be a Linux machine, Windows machine, network device, etc.).
  • Network access: The computer you're connecting from must be able to reach the SSH server's IP or domain, and it's critical that port 22 is open on your firewall.
  • User permits: While being an administrator isn't always essential, in many scenarios you'll need elevated permissions to install features or access remote systems.
  Convert Word documents to EPUB: methods, settings, and security

Check OpenSSH installation and version on Windows

To check if you have the OpenSSH client available on your system, open PowerShell and run:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

The status will show as installed or not present for both the client and the server. If it's not installed, you can add it with:

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

For the server in case you want to enable receiving SSH connections on your own computer:

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

Once installed, you'll be able to use the 'ssh' command directly in PowerShell or Command Prompt.

Configure and start the SSH service on Windows

If you're going to accept SSH connections on Windows, you'll need to make sure the service is started. To start it and configure it to start automatically every time you boot your system, run:

Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'

It is recommended to verify that a firewall rule already exists that allows incoming traffic through port 22 (SSH):

if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
 Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
 New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
 Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}

Getting Started: Connecting via SSH from PowerShell

Once you have everything set up, you can start an SSH session with a simple PowerShell command:

ssh usuario@servidor

Remember to replace 'username' with your username on the remote machine and 'server' with the IP address or DNS name. When you run it, it will ask you to accept the host key (the first time) and the password.

Real example connecting to a Linux server:

ssh [email protected]

You can also connect to other Windows systems with an active SSH server, or to compatible network devices.

Advanced parameters and key authentication

SSH allows for a great deal of flexibility in how you authenticate and establish a connection. The most common parameters are:

  • -i To specify a private key for passwordless authentication: ssh -i ruta/claves/id_rsa usuario@servidor
  • -p To specify a port other than 22: ssh -p 2222 usuario@servidor
  • -v for verbose mode, useful for debugging.
  Methods to reply to phone calls with a text message on iPhone

In PowerShell, you can use keys generated with ssh-keygen and copy them to the remote server for added security and convenience, avoiding passwords.

Manage and automate advanced SSH sessions with PowerShell

Beyond basic commands, PowerShell includes advanced cmdlets for working with SSH sessions, such as New-PSSession, Enter-PSSession, and Invoke-Command . This enhances remote administration, allowing you to automate scripts and maintenance tasks without requiring manual login each time.

  • New-PSSession allows you to create a new remote session by specifying the host, user and password or public key.
  • Enter-PSSession allows you to interactively enter a remote session, executing commands as if you were physically at the other computer.
  • Invoke-Command executes commands or script blocks remotely, ideal for mass administration or automated tasks.

Example to start a session:

New-PSSession -HostName 192.168.1.100 -UserName admin

To enter the created session:

Enter-PSSession -Session $session

You can transfer files, monitor processes, automate tasks, and more, all from the convenience of PowerShell.

Configure SSH Server on Linux and macOS for PowerShell Connections

Not only can you manage Windows computers from PowerShell, but you can also access Linux and macOS servers. On these computers, you'll need to ensure the OpenSSH service is installed and running. Here's how to do it on Linux (e.g., Ubuntu):

sudo apt install openssh-client
sudo apt install openssh-server

To check that it is active:

sudo systemctl status sshd

On macOS, simply enable remote access from 'Sharing' – 'Remote Login' in the system settings.

In both cases, you can edit the sshd_config file to allow password or public key authentication, and even set PowerShell as the default shell.

Useful SSH Commands from PowerShell

Once connected, you can execute a wide range of remote system commands. Some useful examples for daily management:

  • ls / dir: list the contents of a directory
  • cd: change directory
  • touch / New-Item: creates new files
  • rm / Remove-Item: deletes files or folders
  • mv / Move-Item: move or rename files
  • scp: transfers files between client and server
  • useradd: add users
  Complete Guide to Migrating a Linux Server Without Interruptions

These commands enable complete administration, automation, and scripting for repetitive tasks or complex infrastructures.

Advanced configuration and customization of SSH sessions in PowerShell

PowerShell SSH offers many advanced options to customize the experience to suit your needs:

  • Edit the configuration file in $env:ProgramData\ssh\sshd_config to fine-tune authentication, algorithms, rules, and more.
  • Allow or block access by password or public key according to security needs.
  • Add subsystems like PowerShell to have remote sessions start directly in PowerShell using 'Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs -nologo'.
  • Restart services and adjust environment variables so that everything works properly.