Use SSH With Private and Public Keys in VMware ESXi

Page content

Keys

I am a private Linux user since many Years and I always have used combination of username and password to authenticate when logging via Secure Shell (SSH). It worked pretty well for Years but recently as my Linux footprint grew it started to be very tiresome. I knew that there is this “magical way” to login without password but I was reluctant to try it out. Once I tried it out I loved it and I never ever want to user password to authenticate with SSH. In this post you will learn how you can use combination of public and private keys to login to VMware ESXi.

Why should you consider using key based authentication?

Thats a very good question. Public Key Infrastructure Public Key Infrastructure - Wikipedia is a very secure way of generating and using a pair of keys - public and private one. Public key can be shared with everyone and private one should be stored securely. In every modern operating system you can create such a key pair and login to SSH enabled systems.

How to create a public / private key pair?

Generally speaking it is very easy and can be done in several ways. It differes per Operating System.

macOS

In macOS you can do it in terminal of your choice.

  1. Open Terminal.
  2. Type ssh-keygen.
  3. You will be asked where you want to store your keys.
  4. Optionally you can secure your keys with a passphrase.
  5. Pair of keys will be generated.

    Keys in macOS

Linux

In Linux procedure is pretty much the same as in macOS :D

Windows

In Windows keys creation of course might be different based on software you use. In my case I am using free PuTTY to login via SSH. In order to generate SSH keys you need to start software called PuTTY Key Generator - puttygen.exe.

  1. Start puttygen.exe.
  2. Choose type of key you want to generate. I suggest as minimum RSA with 2048 bits.
  3. Click Generate.
  4. You will need to generate some randomness with your mouse.
  5. Once done you can configure authentication with keys in your PuTTY session.

PuTTY Key Generator

Where to store you public keys?

In my case I am using two macOS laptops and one Windows 10 based computer (to play some games). I have different SSH keys on each computer. I added all SSH keys to my GitHub account and whenever I need to retrieve them I simply check them using following command.

wget https://github.com/wojciehm.keys

Add your public keys to VMware ESXi

Procedure is quite simple.

  1. Login to VMware ESXi Server using SSH.
  2. Edit following file /etc/ssh/keys-root/authorized_keys and add your keys.
  3. Execute following command to restart SSH service. /etc/init.d/SSH restart.
  4. Try logging in and mark that you don’t need password anymore.