ESX 4/5 – Grant Root User SSH Access

for ESXi click here

KB ID 0000278 

Problem

ESX is built on Linux – and in the Linux environment, to root user is denied SSH access, there are valid security reasons for this, and you can SSH to the ESX box as a normal user and then issue the “su -” command to switch to root access.

However, some of us still want to SSH in as root, here’s how to do it.

Solution

1. Create a user on your ESX Server (Ensure the user is granted “Shell access”).

2. Connect to your ESX server via SSH (using PuTTy) with the credentials you created above.(Note: if using another SSH client, use SSH2).

3. Execute the following command,

[box]su -[/box]

4. Give it the root password.

5. Execute the following command,

[box]cd /etc/ssh[/box]

6. Execute the following command,

[box]nano sshd_config[/box]

7. Locate the line saying PermitRootLogin no and change it to Yes (Note: Use the arrow keys).

8. Type CTRL+X answer Y for Yes > Then press Enter to confirm.

9. Execute the following commands,

[box]

service sshd restart
esxcfg-firewall -e sshServer
esxcfg-firewall -e sshClient

[/box]

Related Articles, References, Credits, or External Links

NA

ESX – Shut down from Script/Command

KB ID 0000279 

Problem

I was asked the question last week “How do I shutdown my ESX server remotely from script”. The client had a temperature sensor in their server room and wanted to shutdown their ESX host if it got too hot, all his Windows servers got sent an SNMP trap from the temperature sensor, and that fires off a script to shut down the Windows servers. But this left the ESX host up and running.

Solution

I drew a blank on getting a shell script to fire when an SNMP trap is received on ESX, but there’s nothing to stop me adding a line to one of the Windows server scripts that would shut down the ESX server.

1. Firstly get all your Guest VM’s to shutdown automatically when the host is shut down > In the VI client > Select the host > Configuration > Virtual Machine Startup/Shutdown > Properties.

2. Tick the box marked “Allow virtual machines to start and stop automatically with the system” > Change the “Shutdown Action” option from “Power Off” to “Guest Shutdown”.

3. Select Each guest VM and click the “Move Up” button so that are all in the automatic startup section > OK.

WARNING – this is not supported on ESX4 for guest VM’s in a High Availability cluster. (page 22).

4. I’m going to shutdown using the root account, for this to work you need to allow SSH access to the root user see HERE.

5. Download a copy of plink.exe and put it in the same directory as your script (or the system32 directory on the windows machine).

6. Add the following line to the bottom of your script,

[box]plink -ssh root@172.16.254.209 -pw password123 poweroff -p[/box]

Note: where password123 is the root password, and 172.16.254.209 is the IP of the ESX server.

7. When the line is executed, the guest VM’s will shut down, then the ESX Server will power off.

In the VI client you will see the guests shutting down.

Related Articles, References, Credits, or External Links

NA