PowerShell

PowerShell: Use SSH to connect to remote hosts (Posh-SSH)

Posh-SSH is a PowerShell module for Windows 10. The module enables you to establish SSH connections to remote computers. As a prerequisite, Windows Management Framework 5 has to be installed. In this article I am going to show step-by-step how to install Posh-SSH and establish a remote connection to a computer running Linux.

In Windows, SSH connections are somewhat unusual, because PowerShell has it’s own feature, but SSH is indispensable for accessing non-Windows devices, like switches, routers and last but not least Linux machines.

Installation

Run Find-Module to look for the new PowerShell Module Posh-SSH. If you can’t find it, install .NET Framework 5.0 from this source: https://www.microsoft.com/en-us/download/details.aspx?id=50395


Find-Module Posh-SSH

1

Install it by running a simple One-Liner.


Find-Module Posh-SSH | Install-Module

2

Once completed, feel free to explore the new Posh-SSH commands. For the next step, we need only two of them.


Get-Command -Module Posh-SSH

3

Running SSH on Windows PowerShell

Now connect to a remote host using New-SSHSession.


New-SSHSession -ComputerName Server01

42.jpg

Run Get-SSHSession to show all current connections. My connection has Session Id 0. We need this session ID in the next step.


Get-SSHSession

2.JPG

Remote commands are entered by running Invoke-SSHCommand and the Session Id.


Invoke-SSHCommand -SessionId 0 -Command cut -d: -f1 /etc/passwd

1.JPG

Further thoughts

If you like the Windows PowerShell built-in feature “PowerShell Remoting” more, then have a look at my article: PowerShell Remoting: How to connect to Remote Hosts in a Domain- and in a Non-Domain Environment (Trusted Hosts)

Categories: PowerShell

Tagged as: , ,

6 replies »

  1. Thank you for your kindly instruction. Is it possible to use these command to login a server with google f2a authentication? If so, How could I enter the verification code?

    Like

  2. Hi,
    Great website ..

    Could you please help me , how to connect window server to non-windows systems(Unix,LINUX,AIX…) USING power shell scripts..Also i want to transfer files Windows to other operating systems and get files from other operating system to Windows..

    Is there any possibility to do this..?
    Thanks,
    Kannan M

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.