Skip to content

Month: January 2011

Permanently enabling SSH on ESXi via PowerShell

As you all know by now, ESXi comes with SSH, which VMware now refers to as Tech Support Mode, disabled. The reasons behind this include security and the removal of the service console. While the service console has been removed, a shell called BusyBox remains. According to VMware best practice, SSH should not be enabled as it should not be needed. Of course, customers require this kind of access to install agents and to troubleshoot problems. VMware’s response was to enable remote access to the systems via vCenter Server, vMA, or an API and to recommend reinstalling ESXi should troubleshooting become necessary. If you want to read more about this, I would recommend seeing Duncan’s post over at yellow-bricks:
Recently, I ran into an issue where several potential ESXi bugs were discovered, which required SSH access to the ESXi host as the logs were lacking information (one of the reported bugs) and the commands that needed to be executed could not be done remotely (e.g. df -h). As such, I was asked to enable SSH on 64 ESXi hosts. Performing this task manually was not an option so I turned to PowerCLI to automate the task.
This raises the question, how do you enable SSH on ESXi via PowerCLI?

Using diff when the same text is on different lines

I recently ran into an issue where I needed to diff two files and determine what text was different though I did not want text to be marked as different if it appeared on different lines. As an example, if I had the below two files, I wanted diff to return nothing

$ cat file1
Some text Blah
$ cat file2
Blah Some text

To my surprise, when I ran diff it returned:

$ diff file1 file2
1d0 <
Some test
2a2 >
Some test

Looking at the diff man page, the only relevant option I could find was –ignore-all-space, but this flag had no impact on the result of the command. The reason why this option did not work was because it only removed spaces on the same line between the files. For example:

$ cat file3
Some text
$ cat file4
S o me tex t
$ diff file3 file4
1c1 <
Some text
--- >
S o me tex t
$ diff --ignore-all-space file3 file4

Now, you may be wondering why I desired the functionality to diff two files with the same text on different lines. I was trying to create a configuration synchronization script, but I learned that the configuration output was different depending on what order commands were executed on the device. In my particular case, the two devices I was comparing were initially configured differently so the lines did not always match up.
So how do you compare two files where the text is the same, but the text appears on different lines?