Tuesday, March 5, 2013

Passwordless access to a VMware ESXi server

On top of the previous two posts, here’s how to enable password-free access to ESXi (tested with ESXi 5.1).
This is slightly different from an UNIX/Linux server in the sense that the public key has to be stored under /etc/ssh/root-keys directory.

A nifty one-liner exists to achieve the above directly from your local computer (on my Mac):
# cat /Users/<userID>/.ssh/id_rsa.pub | ssh root@<esxi_host> 'cat >> /etc/ssh/keys-root/authorized_keys'

A password, of course, will be asked but this will be the last time. And, yeah, this setting will be reboot-resistant.

Source:
http://blogs.vmware.com/vsphere/2012/07/enabling-password-free-ssh-access-on-esxi-50.html
NOTE: please, pay attention to any security concerns about enabling SSH access in the first place.

Thursday, February 21, 2013

Passwordless access to a *nix host via SSH

Seen this many times but it's worth a new note with some additional comments.
To access "remote server" from "local machine" I always use SSH. To make the process easy and password-free there's a quick method to store on "remote server" the public RSA key for "local machine" so that password won't be asked any longer.
  1. On "local machine" run (tested on OS X 10.8, your output may vary):
    $ ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/<userID_1>/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase): ***
    Enter same passphrase again: ***
    Your identification has been saved in /Users/<userID_1>/.ssh/id_rsa.
    Your public key has been saved in /Users/<userID_1>/.ssh/id_rsa.pub.
    The key fingerprint is:
    <long_hex_string> <userID_1>@<local machine>
    The key's randomart image is:
    ... suppressed output...
  1. The public key, id_rsa.pub, will have to be copied over to "remote server" and added to a file named authorized_keys. To simplify things, let's assume this is the first time we run this process hence id_rsa.pub will become the initial authorized_keys file:
    $ scp .ssh/id_rsa.pub <userID_2>@<remote server>:.ssh/authorized_keys

NOTE: usernames can be different between the two hosts.

Needless to say, next SSH-based authentication (from "local machine" to "remote server") will be done without requiring any passwords.

The relationship between "key fingerprint" and "public key" is also interesting since command ssh-keygen is able to hash the public key returning the host's key fingerprint:
$ ssh-keygen -lf .ssh/id_rsa    
2048 <long_hex_string> <userID_1>@<local machine> (RSA)


Wednesday, February 20, 2013

An all-CLI approach to starting/stopping VMs in ESXi 5.1

You could do that without vSphere client, you knew that?!?

Provided that SSH is enabled on ESXi (link opens another window), log in to the root prompt the follow the steps below:
  1. first, verify that the host is/isn't in Maintenance mode:
    # vim-cmd hostsvc/hostsummary | grep Maintenance
          inMaintenanceMode = false,
  1. obviously, if it is, exit Maintenance mode:
    # vim-cmd hostsvc/maintenance_mode_exit
    'vim.Task:haTask-ha-host-vim.HostSystem.exitMaintenanceMode-415392973'
  1. then, check which VMs are available (output edited):
    # vim-cmd vmsvc/getallvms
    Vmid  Name               File                      Guest OS     Version

    1    name_1  [storage_1] Debian 64 6.x/vmx1.vmx  LinuxGuest     vmx-08
    2    name_2  [storage_2] Windows XP 1/vmx2.vmx   winXPProGuest  vmx-07
    3    name_3  [storage_3] Windows XP 2/vmx3.vmx   winXPProGuest  vmx-08
  1. VMs can be started as follows:
    # vim-cmd vmsvc/power.on 2
    Powering on VM:
Yep, that's all you have to do, no need for vSphere client for the time being :)

Links:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1038043
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=9639912


Monday, February 18, 2013

Start an Apache Web Server in Mac OS X Mountain Lion

In OS X Mountain Lion the Web Sharing preference panel has been removed. The Apache web server remains bundled with Mac OS X though, but you’ll need to turn to the command line to enable the web server.
  1. Create and edit the following file /etc/apache2/users/USERNAME.conf (replace "USERNAME" with the actual account)
  2. Its contents should be as follows:
    <Directory "/Users/USERNAME/Sites/">
    Options Indexes Multiviews
    AllowOverride AuthConfig Limit
    Order allow,deny
    Allow from all
    </Directory>
  3. start the actual server: sudo apachectl start
  4. accessing http://127.0.0.1/ will simply display It works!
  5. files stored under /Users/USERNAME/Sites/ will be accessible from http://127.0.0.1/~USERNAME
  6. stop/restart your Apache web server with sudo apachectl stop|restart
Source: http://osxdaily.com/2012/09/02/start-apache-web-server-mac-os-x/

More info here: http://reviews.cnet.com/8301-13727_7-57481978-263/how-to-enable-web-sharing-in-os-x-mountain-lion/
and here: http://coolestguyplanettech.com/downtown/install-and-configure-apache-mysql-php-and-phpmyadmin-osx-108-mountain-lion



Wednesday, February 6, 2013

How to convert .plist files between XML and binary

  • To convert a binary .plist file to XML format for editing, type this in Terminal.app:
plutil -convert xml1 <file>.plist

  • To convert back an XML .plist file to binary format use: