[Tutorial] Connect SSH Using Windows PowerShell

PowerShell Remote SSH Techhyme

PowerShell Remoting allows you to execute PowerShell commands or scripts on remote computers. It enables you to manage and administer remote systems from a single computer.

PowerShell Remoting provides various useful features like background jobs, remote script execution, and remote module management. You can learn more about these features and additional remoting cmdlets in the official PowerShell documentation.

Also Read: PowerShell Books

Remember, PowerShell Remoting requires administrative privileges and proper network connectivity between the local and remote computers. Ensure that you have the necessary permissions and firewall rules configured to establish remote connections.

Assuming you are on Windows 10 with PowerShell 7 installed. Lets verify it once.

Command: Get-Host | Select-Object Version

Windows powershell SSH Linux Techhyme

As you can see that, the current PowerShell version is 5 but for PowerShell Remoting, your minimum version should be 7 at least.

So download the PowerShell 7 version from GitHub repository.

Windows powershell SSH Linux Techhyme

Extract the folder

Windows powershell SSH Linux Techhyme

And run pwsh.exe file by double clicking on it.

Windows powershell SSH Linux Techhyme

Now verify the version of PowerShell by running the following command:

Command: Get-Host | Select-Object Version

Windows powershell SSH Linux Techhyme

To get a list of all available commands, you can run:

Command: Get-Command

Windows powershell SSH Linux Techhyme

dd

Windows powershell SSH Linux Techhyme

To make a connection from Windows machine to Linux machine, the command is:

Command: New-PSSession -Hostname 192.168.1.13 -UserName techhyme

Windows powershell SSH Linux Techhyme

If you try to make a SSH session with Linux machine you may receive an error message like this.

New-PSSession: [192.168.1.13] The SSH Client session has ended with error message: The SSH transport process has abruptly terminated causing this remote session to break.

Next step is to install Open SSH client and server on Windows 10.

Lets use the PowerShell utility Add-WindowsCapabillity and run the commands.

Command: Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Command: Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Windows powershell SSH Linux Techhyme

Once OpenSSH is installed successfully, you need to start the OpenSSH Services by running the following command:

Command: Start-Service sshd

Windows powershell SSH Linux Techhyme

If you want to start the “sshd” service automatically when the computer boots up, then the command is:

Command: Set-Service sshd -StartupType Automatic

Windows powershell SSH Linux Techhyme

Now, Edit the OpenSSH configuration sshd_config located in C:\Windows\System32\OpenSSH or you can find it in C:\ProgramData\ssh\sshd_config by adding Subsystem for PowerShell.

Subsystem powershell pwsh.exe -sshs -NoLogo -NoProfile

Windows powershell SSH Linux Techhyme

Also make sure OpenSSH configuration file sshd_config has PasswordAuthentication set to yes.

Restart the service by using:

Command: Get-Service -Name sshd | Restart-Service

Windows powershell SSH Linux Techhyme

SSH remoting is now properly set on your Windows Machine.

You may also like:

Related Posts

Leave a Reply