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.
In macOS you can do it in terminal of your choice.
- Open Terminal.
- You will be asked where you want to store your keys.
- Optionally you can secure your keys with a passphrase.
- Pair of keys will be generated.
In Linux procedure is pretty much the same as in macOS :D
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.
- Start puttygen.exe.
- Choose type of key you want to generate. I suggest as minimum RSA with 2048 bits.
- Click Generate.
- You will need to generate some randomness with your mouse.
- Once done you can configure authentication with keys in your PuTTY session.
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.
Add your public keys to VMware ESXi
Procedure is quite simple.
- Login to VMware ESXi Server using SSH.
- Edit following file /etc/ssh/keys-root/authorized_keys and add your keys.
- Execute following command to restart SSH service.
- Try logging in and mark that you don’t need password anymore.