使用 PowerShell 中的 New-SshSession(使用私钥)远程登录 Linux 失败,并显示“无效的私钥文件" [英] Remotely login to Linux using New-SshSession in PowerShell (with a private key) fails with "Invalid private key file"
问题描述
我正在尝试使用带有下面列出的 3 个输入的密钥从 Windows PowerShell 登录到 Linux 服务器.
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]
我收到了一位同事的私钥文本,我需要知道如何实现.将其保存在 .ppk
文件中没有产生任何结果.PowerShell 在运行上面的行时会吐出以下内容.
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?
谢谢!
推荐答案
手册 声明 New-SshSession
接受用于启动和验证 SSH 连接的 OpenSSH 密钥文件.如果您获得了一个文本文件,您可以通过 PuttyGen.exe(从页面抓取的链接),然后将 .ppk 加载到 PuttyGen 中,然后复制并粘贴生成的数据.如果您收到一个 HEX2BIN 字符串(其中只有 0213456789ABCDEF
的字符串),您必须将其转换为 Base64 字符串.(为此使用 https://www.base64decode.com/ 或类似服务.)
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.)
如果您无法创建兼容文件,请向发行人请求一个以 ssh-rsa
开头的文本文件,可能会将本手册链接到他.
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.
这篇关于使用 PowerShell 中的 New-SshSession(使用私钥)远程登录 Linux 失败,并显示“无效的私钥文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!