2

Am trying to log on to Linux servers from Windows PowerShell using a key with the 3 inputs listed below.

New-SshSession -ComputerName [name] Username- [user] -KeyFile [path]

I've been sent the text for a private key from a colleague and need to know how to implement that. Saving it in a .ppk file hasn't yielded any results. PowerShell spits out the following in response to running the line above.

New-Object : Exception calling ".ctor" with "1" argument(s): "Invalid private key file."
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\SSH-Sessions\SSH-Sessions.psm1:90 char:20
+             $Key = New-Object Renci.SshNet.PrivateKeyFile( $Keyfile ) -ErrorActi ...
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

So I guess I need to know how to save the string I've been sent as a key?

Thanks!

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
beatsandbosons
  • 39
  • 1
  • 10

1 Answers1

1

The manual states that New-SshSession accepts an OpenSSH key file for initiating and authenticating SSH connections. If you have been given a text file, you can make it into a compatible key file via PuttyGen.exe (link grabbed from page), then you load the .ppk into PuttyGen, then copy&paste generated data. If you've received a HEX2BIN string (the one that has only 0213456789ABCDEF in it), you have to convert that into a Base64 string. (use https://www.base64decode.com/ or a similar service for that.)

If you'd fail to create a compatible file, request a text file starting with ssh-rsa from the issuer, probably linking this manual to him.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Vesper
  • 18,599
  • 6
  • 39
  • 61
  • Thanks for the link. Works no problem now. – beatsandbosons Jul 06 '15 at 13:41
  • Correct. Except the advice to paste your *private* key to an online service like base64decode.com is a terrible security flaw. – Martin Prikryl Mar 09 '21 at 06:37
  • @MartinPrikryl Agreed, although if a private key is not provided with an exact instruction on how to stuff it into a particular piece of software that's known to be used by an addressee, the infrastructure is of insufficient significance for this security flaw to really matter. – Vesper Mar 09 '21 at 07:35