How to Setup SSH key for VMware ESXi

How to Setup SSH key for VMware ESXi
⚠️
Disclaimer: This content is created solely for educational and training purposes. It does not constitute a response to any actual security issue, breach, or operational risk, and should not be interpreted as incident handling guidance.

1. Generate SSH Key (from your workstation)

On your Linux/Mac machine (or Windows with Git Bash/WSL/PowerShell):

ssh-keygen -t rsa -b 4096
  • Save it in ~/.ssh/id_rsa (default).
  • This creates:
    • id_rsa → private key (keep safe, use this key to SSH to ESXi server).
    • id_rsa.pub → public key (to copy to ESXi).

2. Enable SSH on ESXi

  1. Log in to the ESXi Web UI (https://<esxi-host-ip>/ui).
  2. Go to Host → Actions → Services → Enable Secure Shell (SSH).
    (Or enable via DCUI: Troubleshooting Options → Enable SSH)

3. Create the .ssh Directory on ESXi

SSH into your ESXi host with your password once:

ssh root@<esxi-host-ip>

Then run:

mkdir -p /etc/ssh/keys-root

Exit ESXi SSH session:

exit

4. Copy Public Key to ESXi

From your workstation (Ensure you have existed VMware SSH):

scp ~/.ssh/id_rsa.pub root@<esxi-host-ip>:/etc/ssh/keys-root/authorized_keys

On the ESXi host:

chmod 600 /etc/ssh/keys-root/authorized_keys

5. Test Connection

From your workstation:

ssh root@<esxi-host-ip>

You should be logged in without a password prompt.

6. Persist Across Reboots

ESXi does not persist custom files in /etc and SSH connection after reboot. To make sure the authorized_keys file survives:

  1. Create a startup script:
vi /etc/rc.local.d/local.sh
  1. Add this before the final exit 0 line, hit 'i' to insert the text, ':wq' to save change, ':q!' exist without save:
vim-cmd hostsvc/enable_ssh
cp /store/authorized_keys /etc/ssh/keys-root/authorized_keys
chmod 600 /etc/ssh/keys-root/authorized_keys
  1. Save your public key copy into /store/authorized_keys (which is persistent):
mkdir -p /store
cp /etc/ssh/keys-root/authorized_keys /store/authorized_keys
  1. Make the script executable:
chmod +x /etc/rc.local.d/local.sh
  1. Reset VMware and Test SSH Login From Workstation:
ssh root@<esxi-host-ip>

If you found this guide helpful, consider supporting me!

Read more