With Power­Shell SSH, you can access and manage remote systems from virtually anywhere. In addition, SSH offers detailed logging functions that allow activ­it­ies on the server to be com­pre­hens­ively monitored and tracked.

What are the re­quire­ments for Power­Shell SSH?

In­teg­rat­ing SSH in Windows Power­Shell gives you the ability to establish SSH con­nec­tions to remote systems and execute SSH commands in a Power­Shell script. This makes it a lot easier to manage and automate tasks in dis­trib­uted IT in­fra­struc­tures, es­pe­cially in a het­ero­gen­eous en­vir­on­ment where there are both Windows and non-Windows systems.

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

  • Power­Shell in­stall­a­tion: Make sure that Power­Shell v6 or higher is installed on your local computer. Power­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 Power­Shell en­vir­on­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.
  • Power­Shell modules: There are Power­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­res­pond­ing module is installed on your system in order to be able to use SSH func­tion­al­ity in Power­Shell.
  • Au­thor­isa­tions: You need ad­min­is­trat­or or elevated priv­ileges and a password or SSH key to establish SSH con­nec­tions from your local computer and access the remote server.
Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

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

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

Step 1: Install OpenSSH

Click on the start menu or enter ‘Power­Shell’ in the search bar. Select Run as ad­min­is­trat­or. This opens the Windows Power­Shell. You can use the following Power­Shell command to install the OpenSSH feature on your Windows computer:

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

Step 2: Start OpenSSH service

Once the in­stall­a­tion is complete, you can start the OpenSSH service:

Start-Service sshd
power­shell

You can check whether the OpenSSH service is running:

Get-Service sshd
power­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 auto­mat­ic­ally

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

Set-Service -Name sshd -StartupType 'Automatic'
power­shell

Step 4: Customise 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
power­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 Power­Shell on your client PC and enter the SSH command with the username and server address.

ssh username@servername
power­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­tic­a­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­ic­ally logged on to the server. To end the SSH session and return to the local Power­Shell, you can use the exit command.

There are a number of SSH commands in Power­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 Power­Shell

Here is a list of commands that you can use in Power­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 dir­ect­or­ies
  • mv/Move-Item: Moves or renames files and dir­ect­or­ies
  • useradd: Adds a new user
  • scp: Transfers files between client and server

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

Go to Main Menu