SID-500

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

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)


4 Comments

  1. […] If you don’t like SSH, use the PowerShell built-in remote feature, which I have described in my article: PowerShell: Use SSH to connect to remote hosts (Posh-SSH) […]

    Like

  2. Kannan M says:

    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

  3. […] PowerShell: Use SSH to connect to remote hosts (Posh-SSH) […]

    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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Categories

WHOIS

My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on WordPress.com