2017-09-24 2 views
0

나는 puttygen을를 사용하여 SSH 키 쌍을 생성하고 성공적으로 내 Windows 10 워크 스테이션에서 퍼티에서 내 개인 키를 내 CentOS는 서버에 연결할 수 있습니다PowerShell의 개인 키로 ssh를 사용하여 Linux 서버에 연결하는 방법은 무엇입니까?

image of successful connection to CentOS

내가의 Windows PowerShell에서 서버에 연결하려면

$Credential = Get-Credential 
$KeyFile = 'C:\Users\mark\Documents\ssh\privkey.ppk' 
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -Keyfile $KeyFile 

: 내가 가진 새로운 SSH 세션을 만들려고 한 Install-Module posh-ssh

와 포쉬 - SSH 모듈을로드 한

New-SSHSession : Invalid private key file.

내가 그것을 읽고 base64 인코딩으로 변환하여 문자열로 privkey 파일을 변환하려하지만이 같은 얻을 : 나는이 오류가

Get-Credential에 대한 루트 빈 암호를 넣어 오류 :

$privkeyString = Get-Content $KeyFile 
$Bytes = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($privkeyString)) 
$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $Bytes 

는 또한

$sesh = New-SSHSession -ComputerName neon.localdomain -Credential $credential -KeyString $privkeystring 
시도

하지만 같은 오류가 발생합니다.

PowerShell을 개인 키 파일과 함께 사용하여 Linux 서버에 연결하는 방법에 대한 아이디어가 있습니까?

답변

2

New-SSHSession은 PuTTY의 키 형식을 인식하지 못합니다 (불행히도 갤러리 나 프로젝트 페이지에는 언급하지 않았지만 PowerShellMagazine article에서 찾았습니다). 개인 키는 OpenSSH 형식이어야합니다. 당신은 PuTTYgen을 함께 convert the private key 수 있습니다

  1. 클릭 파일 →로드 키 개인.
  2. 키가 암호로 보호되어 있으면 암호를 입력하십시오.
  3. 클릭 전환 → 내보내기 OpenSSH 키.
  4. 내 보낸 키의 파일 이름을 입력하고 (PPK 파일을 덮어 쓰지 않음) 을 클릭하십시오.
  5. Exit PuTTYgen. 새 키 파일을

실행 New-SSHSession :

$computer = 'neon.localdomain' 
$username = 'foo' 
$keyfile = 'C:\path\to\priv_openssh.key' 

$sess = New-SSHSession -Computer $computer -Credential $username -Keyfile $keyfile