Mar*_*son 3 ssh powershell powershell-5.0
我已经使用puttygen生成了一个ssh密钥对,并且可以使用Windows 10工作站上的putty的私钥成功连接到CentOS服务器:
我想从Windows PowerShell连接到服务器,并使用以下命令加载了Posh-SSH模块: Install-Module posh-ssh
我尝试使用以下命令创建一个新的ssh会话:
$Credential = Get-Credential
$KeyFile = 'C:\Users\mark\Documents\ssh\privkey.ppk'
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -Keyfile $KeyFile
Run Code Online (Sandbox Code Playgroud)
我输入了root和空白密码,Get-Credential但出现此错误:
New-SSHSession:无效的私钥文件。
我试图通过读取私钥文件并将其转换为以base64编码的方式将privkey文件转换为字符串,但出现相同的错误:
$privkeyString = Get-Content $KeyFile
$Bytes = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($privkeyString))
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $Bytes
Run Code Online (Sandbox Code Playgroud)
我也试过了,但是得到了同样的错误:
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $privkeystring
Run Code Online (Sandbox Code Playgroud)
关于如何使用带有私钥文件的PowerShell连接到linux服务器的任何想法?
New-SSHSession无法识别PuTTY的密钥格式(不幸的是,Gallery和项目页面均未提及此格式,但我在PowerShellMagazine文章中找到了它)。您需要采用OpenSSH格式的私钥。您可以使用PuTTYgen 转换私钥:
New-SSHSession使用新的密钥文件运行:
$computer = 'neon.localdomain'
$username = 'foo'
$keyfile = 'C:\path\to\priv_openssh.key'
$sess = New-SSHSession -Computer $computer -Credential $username -Keyfile $keyfile
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3076 次 |
| 最近记录: |