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:Windowssystem32WindowsPowerShellv1.0ModulesSSH-SessionsSSH-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!
Advertisement
Answer
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.