Allowing SSH access to ESXi/ESX hosts with public/private key authentication
search cancel

Allowing SSH access to ESXi/ESX hosts with public/private key authentication

book

Article ID: 313767

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides steps to allow SSH access to ESXi/ESX hosts with public/private key authentication rather than with username/password authentication.


Environment

VMware vSphere ESXi 6.7
VMware vSphere ESXi 6.5
VMware vSphere ESXi 5.5
VMware vSphere ESXi 6.0

Resolution

Note: ESXi 7.0 does not support preserving SSH-Keys for non-root users.

To allow SSH access to ESXi or ESX hosts with public/private key authentication:

  1. Generate public/private keys on ESXi. For more information, see the OpenBSD Reference Manual section in the OpenBSD.

    Note: The preceding link was valid as of June 22, 2016. If you find the link to be broken, provide feedback on the article and a VMware employee will update the article as necessary.

    Notes:
    • These instructions generate two files in ~/.ssh: id_rsa and id_rsa.pub.
    • Starting from ESXi 5.x, the ssh-keygen command is located at /usr/lib/vmware/openssh/bin.
       
  2. On the ESXi host, store the public key content, id_rsa.pub in ~/.ssh/authorized_keys. (e.g. cat id_rsa.pub >> authorized_keys)

    Notes:
    • For ESXi 5.x, 6.0, 6.5, 6.7 and 7.0, the authorized_keys is located at: /etc/ssh/keys-<username>/authorized_keys
    • More than one key can be stored in this file.
       
  3. To allow root access, change PermitRootLogin no to PermitRootLogin yes in the /etc/ssh/sshd_config file.
  4. To disable password login, ensure that the ChallengeResponseAuthentication and PasswordAuthentication are set to no.
  5. Reload the service:
    • For ESXi, run the command:
      # /etc/init.d/SSH restart
    • For ESX, run the command:
      # service sshd reload
          6.  Copy id_rsa to local desktop, and use it as private key to SSH ESXi host

    Additional Information

    For more information on SSH, see Uploading an SSH Key to Your ESXi Host section in the VMware vSphere 5.5 documentation Center.


    Additional Information

    For translated versions of this article, see: