Saturday, August 29, 2015

PowerShell Password-less SSH to Linux

Using Powershell version 3:

PS C:\Windows\system32> $PSVersionTable
Name                           Value
----                           -----
WSManStackVersion              3.0
PSCompatibleVersions           {1.0, 2.0, 3.0}
BuildVersion                   6.2.9200.16398
PSVersion                      3.0
CLRVersion                     4.0.30319.1
PSRemotingProtocolVersion      2.2

PS C:\Windows\system32> $PSVersionTable.PSVersion
Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      -1     -1
Download SSH-Session module from:
In Download Section:
Extract and this creates:

Get the Module Paths:

PS C:\Windows\system32> $env:PSModulePath

This is module extention path: C:\Users\rumman\Documents\WindowsPowerShell\Modules
Copy "C:\Downloads\SSH-SessionsPSv3\SSH-Sessions" To "C:\Users\rumman\Documents\WindowsPowerShell\Modules"

Now, in shell prompt, use the following command to ensure that the module is available:
PS C:\Windows\system32> Get-Module *ssh*
ModuleType Name                                ExportedCommands
---------- ----                                ----------------
Script     SSH-Sessions                        {ConvertFrom-SecureToPlain, Enter-SshSession, Get-SshSession, 
PS C:\Windows\system32> Get-Command *ssh*
CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Function        Enter-SshSession                                   SSH-Sessions
Function        Get-SshSession                                     SSH-Sessions
Function        Invoke-SshCommand                                  SSH-Sessions
Function        New-SshSession                                     SSH-Sessions
Function        Remove-SshSession                                  SSH-Sessions

Import Module:

PS C:\Users\rumman> Import-Module SSH-Sessions
Import-Module : Could not load file or assembly
'file:///C:\Users\rumman\Documents\WindowsPowerShell\Modules\SSH-Sessions\Renci.SshNet.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At line:1 char:1
+ Import-Module SSH-Sessions
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

I faced the above issue and what I did unblocking the file.
Go to C:\Users\rumman\Documents\WindowsPowerShell\Modules\SSH-Sessions
There are 3 files:
- Renci.SshNet.dll
- SSH-Sessions.psd1
- SSH-Sessions.psm1

For each file, right-click -> Properties -> Unblock
Then, load the module again:
PS C:\Users\rumman> Import-Module SSH-Sessions
PS C:\Users\rumman>

Verify SSH Connection:

PS C:\Users\rumman> New-SSHSession -ComputerName "" -Username "postgres"
No key provided. Enter SSH password for postgres: ******
Successfully connected to
PS C:\Users\rumman> Get-Session

PS C:\Users\rumman> Get-SSHSession
ComputerName                                                                                                  Connected
------------                                                                                                  ---------                                                                                                          True

PS C:\Users\rumman> Remove-SSHSession -ComputerName "" should now be disconnected and disposed.

Setup Password-less SSH:

Download Putty.exe and Puttygen.exe. One of the sites for this:

There are lots of sites available to describe the steps to use puttygen to setup password-less ssh.
For example,
I saved the private key at  C:\putty\private_key.ppk
And also use the menu conversion->export OpenSSH
and save it as exported_openssh_key
This key is usable for other application.

When password-less ssh is working form Putty, now try from powershell:
PS C:\Users\rumman> New-SSHSession -ComputerName "" -UserName "postgres" -KeyFile C:\putty\exported_openssh_key
Key file specified. Will override password. Trying to read key file...
PS C:\Users\rumman> Get-SSHSession
ComputerName                                                                                                  Connected
------------                                                                                                  ---------                                                                                                          True

3 Responses so far

  1. Thanks for sharing this information Freyr Energy was founded on the principles of making solar energy affordable and accessible for everyone. In order to make adoption of solar energy a reality at the grass-root level, we have identified that consumer awareness, affordability and accessibility play an integral role. With our innovative platform, SunPro+, our extensive channel-partner network and our efficient service we ensure that these three factors are addressed to make sure your venture into solar energy is hassle-free. Best solar company in Hyderabad-freyr

  2. ksac says:

    Thanks for sharing this information KSAC is one of the most trusted multi-specialty Ayurvedic hospitals in India. For over two decades, we provides 100% Evidence based Treatments for diseases, Naturally.Best Ayurveda Hospital in Hyderabad, Bengalore, India

  3. Our Busty Call Girls in Manali are wonderful in offering facilities of the unusual standard.Call Girls near Manali Airport These babes are too sexy in appearance and wear short outfits to capture the attention of males.Air hostess Escorts in Agra These babes use a lot of makeup on their face and are too friendly with males.Real Call Girls Photo in Dehradun If you are seeking the Real Call Girls Photo in Dehradun right babe to offer you excellent sensuality then certainly look for these Hot High Profile Escorts in Faridabad.

Leave a Reply