There are more than one way to enable SSH on your esxi hosts in your vmware environment. One of them is via the DCUI (Direct Console User Interface). One of the ways to do that remote is with SSH. Enabling SSH can be done from the GUI, but since that’s not the goal of PowerShell we’re going to do this the PowerCLI way. Another quick blog post on how to Enable or Disable SSH on ESXi Hosts VMhost Using Powershell or Powercli.
What is SSH
SSH, or Secure Shell, is a way to get into a ESXi or Linux host throug the network, so you can enter commands and get the output without entering your data center. SSH encrypts the connection so no clear text information is sent to and from the ESXi host.
Enabling SSH
If you want to enable SSH on all hosts in your vCenter, you can use the oneliner below.
$cred = Get-Credential
$vcenters = "lab-vc01.lab.local", "lab-vc02.lab.local"
Connect-VIServer $vcenters -Credential $cred
## Note that you will need to connect to vCenter First
Get-VMHost | Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
Via a more refined script way. Save this as start-ssh-vmhosts.ps1 file and run
$cred = Get-Credential
$vcenters = "lab-vc01.lab.local", "lab-vc02.lab.local"
Connect-VIServer $vcenters -Credential $cred
param(
[Parameter(Mandatory=$true)][string]$ESXiHost
)
$ServerName = "*$ESXiHost*"
## Starting Esxi ssh on above specified host
Get-VMHost -Name $ServerName| Foreach {Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}
Disabling SSH
If you want to disable SSH on all hosts still running SSH, you can use the following: Save this as stop-ssh-vmhosts.ps1 file and run
param(
[Parameter(Mandatory=$true)][string]$ESXiHost
)
$ServerName = "*$ESXiHost*"
## Starting Esxi ssh on above specified host
Get-VMHost -Name $ServerName| Foreach {Stop-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq "TSM-SSH"} )}