Powershell

How to Install and Use PowerShell SSH

SSH protocol allows computers to communicate with remote servers. It enables the computers to share data securely over an unsecured network. It lets you log on to remote Linux servers and control them. Users can create a remote session between Linux and Windows computers. SSH allows you to control the Windows machine remotely. Before SSH, Windows users were limited to connecting with the Windows server. However, after the release of the PowerShell SSH client Windows users can now access the Linux computers remotely.

Quick Outline:

Install PowerShell SSH

Before installing PowerShell SSH, you must have the PowerShell version 6 or higher. PowerShell SSH does not come preinstalled on Windows.

Note: Make sure you have the updated PowerShell version on your machine.

1. Check the Availability of OpenSSH Client

Before installing the SSH client, make sure it isn’t already installed. To check its availability execute the given command:

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

To check the SSH client availability:

  • First, write the Get-WindowsCapability command and place the -Online parameter.
  • Pipe the command to the Where-Object command and place the Name alongside it.
  • Then, use the -like parameter and specify the OpenSSH value with an asterisk added to it.
  • This command will find all the components that gave the OpenSSH name:

Note: The State NotePresent in both components confirms that they are not installed on Windows. Move to the section 1 and 2 to install both of the missing SSH components.

2. Install OpenSSH Client

Execute this code to install the PowerShell SSH client:

Add-WindowsCapability -Online -Name OpenSSH.Client

According to the above code:

  • First, write the Add-WindowsCapability command and specify the -Online parameter.
  • Then, use the -Name parameter and provide the OpenSSH.Client command:

3. Install OpenSSH Server

Execute this code to install the PowerShell SSH server:

Add-WindowsCapability -Online -Name OpenSSH.Server

Connect to the SSH Server

To connect with the remote computers third-party tools like WinRM and Putty are used in Windows. But after the Windows 2018 update, PowerShell got the built-in SSH client. This means that now you can connect to the Linux server straight from Windows PowerShell.

1. Start SSH Service

Once the SSH components are installed, then, start the SSH service, with the aid of this command:

Start-Service sshd

2. Connect to the Remote SSH Server

It is time to connect from your PowerShell SSH client to a Windows server, or Linux server.

ssh "domain\username@servername"

To connect with the remote SSH server, first, use the SSH command and then specify the remote server address.

Uninstall PowerShell SSH

Once you are done with SSH server services, you can remove the SSH client and server from Windows using PowerShell easily. The Remove-WindowsCapability command removes the Windows capability package.

1. Uninstall the OpenSSH Client

To remove the SSH client from the computer execute this command:

Remove-WindowsCapability -Online -Name OpenSSH.Client

To remove the SSH client from Windows:

  • First, place the Remove-WindowsCapability command along with the -Online parameter.
  • Then, specify the OpenSSH.Client to the -Name parameter.

2. Uninstall the OpenSSH Server

To remove the SSH server from the computer execute this command:

Remove-WindowsCapability -Online -Name OpenSSH.Server

Note: The code explanation to remove the SSH server is the same as for the SSH client except for the value specified in the -Name parameter.

Conclusion

An SSH network protocol enables the communication of two machines over an unsecured network. SSH protocol lets you access and control the Linux server from PowerShell remotely. Before the PowerShell SSH client, Windows users used to connect with remote servers using third-party tools. However, after the 2018 Windows update, PowerShell got the support for the SSH client.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.