Powershell: how to set up a public/private key pair

Powershell: how to set up a public/private key pair using Windows and puttygen.exe.

  • Download puttygen.exe, open it and click Generate to generate a private/public key pair. I set the number of key bits to 4096.

SSH-from-PowerShell-ESXi-key-generation.png

  • Then export the private key for use with the SSH-Sessions module (has to be in OpenSSH format – the Putty key format will not work as of 2013-09-14).
    • Use the menu choice Conversions -> Export OpenSSH Key.

SSH-from-PowerShell-ESXi-key-generation-putty.png

# echo 'YOUR KEY HERE' >> /etc/ssh/keys-root/authorized_keys

Then connect specifying the key you exported from puttygen.exe earlier:

PS E:\temp> New-SshSession -Computer 192.168.1.103 -KeyFile E:\temp\esxi-key-openssh.key
            -Username root
Key file specified. Will override password. Trying to read key file...
Successfully connected to 192.168.1.103
PS E:\temp> Invoke-SshCommand -Computer 192.168.1.103 -Command 'uname -a' -q
VMkernel esxi 5.1.0 #1 SMP Release build-799733 Aug  1 2012 20:03:00 x86_64 GNU/Linux
PS E:\temp>

SSH-from-PowerShell-ESXi-key-generation-successful-connection.png

twitterlinkedinmailtwitterlinkedinmail
Arco

About

View all posts by