With Pow­er­Shell SSH, you can access and manage remote systems from virtually anywhere. In addition, SSH offers detailed logging functions that allow ac­tiv­i­ties on the server to be com­pre­hen­sive­ly monitored and tracked.

What are the re­quire­ments for Pow­er­Shell SSH?

In­te­grat­ing SSH in Windows Pow­er­Shell gives you the ability to establish SSH con­nec­tions to remote systems and execute SSH commands in a Pow­er­Shell script. This makes it a lot easier to manage and automate tasks in dis­trib­uted IT in­fra­struc­tures, es­pe­cial­ly in a het­ero­ge­neous en­vi­ron­ment where there are both Windows and non-Windows systems.

Here are the re­quire­ments to use SSH in Pow­er­Shell:

  • Pow­er­Shell in­stal­la­tion: Make sure that Pow­er­Shell v6 or higher is installed on your local computer. Pow­er­Shell is usually pre-installed in Windows, but you need to check that you are using a version that supports SSH.
  • SSH client: You need an SSH client in your Pow­er­Shell en­vi­ron­ment to establish SSH con­nec­tions. OpenSSH is available by default in Windows 10/11 and Windows Server 2019. If you are using an older version of Windows, you may need to install OpenSSH manually.
  • SSH server: The SSH server is the target server that you want to connect to. This can be a Linux server, a network device or another SSH-capable host.
  • Network access: Your local computer should have access to the network and be able to reach the remote SSH server. Port 22 must be open for SSH in the firewall rules.
  • Pow­er­Shell modules: There are Pow­er­Shell modules that have been specially developed for the use of SSH, such as the “PSSession” or “Posh-SSH” module. You should check that the cor­re­spond­ing module is installed on your system in order to be able to use SSH func­tion­al­i­ty in Pow­er­Shell.
  • Au­tho­riza­tions: You need ad­min­is­tra­tor or elevated priv­i­leges and a password or SSH key to establish SSH con­nec­tions from your local computer and access the remote server.
Dedicated Servers
Per­for­mance through in­no­va­tion
  • Dedicated en­ter­prise hardware
  • Con­fig­urable hardware equipment
  • ISO-certified data centers

Step-by-step in­struc­tions on how to use Pow­er­Shell SSH

Before you can use Secure Shell (SSH) in Pow­er­Shell, you must set up the OpenSSH server. You can then start the Pow­er­Shell SSH session and execute commands on the remote system.

Step 1: Install OpenSSH

Click on the start menu or enter “Pow­er­Shell” in the search bar. Select Run as ad­min­is­tra­tor. This opens the Windows Pow­er­Shell. You can use the following Pow­er­Shell command to install the OpenSSH feature on your Windows computer:

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
pow­er­shell

Step 2: Start OpenSSH service

Once the in­stal­la­tion is complete, you can start the OpenSSH service:

Start-Service sshd
pow­er­shell

You can check whether the OpenSSH service is running:

Get-Service sshd
pow­er­shell

The Running status indicates that sshd is running properly.

Image: PowerShell: SSH server service
Get-Service sshd checks the execution of the SSH service.

Step 3: Start SSH server service au­to­mat­i­cal­ly

To activate the OpenSSH server service every time Windows is restarted, you can enter the following command:

Set-Service -Name sshd -StartupType 'Automatic'
pow­er­shell

Step 4: Customize firewall

If Windows firewall is active, you should add a rule to allow SSH traffic on Port 22 (the default SSH port).

New-NetFirewallRule -Name 'OpenSSH-Server' -DisplayName 'OpenSSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
pow­er­shell

Step 5: Establish an SSH con­nec­tion

You can now log in with your SSH server from another device. To do this, open Pow­er­Shell on your client PC and enter the SSH command with the username and server address.

ssh username@servername
pow­er­shell

Replace “username” with your SSH username and “server­name” with the IP address or hostname of the remote server. When you start the command, you will be prompted to enter your SSH password unless you are using the SSH key for au­then­ti­ca­tion.

Image: PowerShell: SSH login
Enter the SSH password

Step 6: Work in the SSH session

Once you have es­tab­lished an SSH con­nec­tion, you can execute commands on the remote server as if you were phys­i­cal­ly logged on to the server. To end the SSH session and return to the local Pow­er­Shell, you can use the exit command.

There are a number of SSH commands in Pow­er­Shell. The command pwd stands for “print working directory” and shows you the current working directory, for example:

Image: PowerShell SSH commands using PWD as an example
Example for SSH commands in Pow­er­Shell

Here is a list of commands that you can use in Pow­er­Shell SSH:

  • ls/dir: Displays the contents of a directory
  • cd: Changes the directory on the remote server
  • touch/New-Item: Creates a new file
  • rm/Remove-Item: Deletes files or di­rec­to­ries
  • mv/Move-Item: Moves or renames files and di­rec­to­ries
  • useradd: Adds a new user
  • scp: Transfers files between client and server

You can find more commands in our overview of Pow­er­Shell commands.

Go to Main Menu