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

The ability to connect via SSH directly from PowerShell It is no longer a task reserved for administration gurus. Today, any Windows user can access, manage servers, and even automate tasks through a terminal SSH is supported thanks to native integrations in Windows 10 and later. The path to do so is not only simpler than ever, but has also been refined in terms of stability and security, making it a robust alternative to traditional external clients.

If you have ever needed to manage a remote system, copy files, review logs o run commands on a server Linux or Windows without leaving your desktop, this detailed guide will serve as a reference. You'll learn everything from the requirements, installation, and configuration of OpenSSH on different platforms to practical examples with 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 you to access and manage remote systems using a terminal.Its biggest advantage over other protocols like Telnet is end-to-end encryption, which ensures that all information, including usernames and passwords, travels completely protected.

PowerShell, on the other hand, is the advanced Windows command console, used for both user and administrative tasks. For several years now, Windows has included a native SSH client, allowing you to take full advantage of SSH's power 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.
  iPhone Display screen Turned Black and White: Find out how to Repair?

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*'

You will see the status installed (Installed) or not present (NotPresent) 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 validate 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 'user' with your username on the remote machine and 'server' with the IP 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 root@192.168.1.100

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 a lot of flexibility in how you authenticate and how you 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.
  The way to Use Google Maps Offline On Android Telephone

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 the basic command, PowerShell incorporates advanced cmdlets to work with SSH sessions such as New-PSSession, Enter-PSSession and Invoke-CommandThis enhances remote administration, allowing you to automate scripts and maintenance tasks without the need to log in manually 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
  Windows 10106 Driver Error 10: What Can I Do?

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.