Monday, January 21, 2013

How to reset root password in ESXi 4.x & 5.x

This guide is unsupported from VMware, so do it on your own risk.
First download a live Linux boot CD. In my case I downloaded Knoppix.
Then you can burn the ISO to make a bootable cdrom or use a tool like Live Linux USB Creator to make a bootable Linux USB stick.
Boot with above Linux boot CD or USB and enter
# fdisk -l
to find the disks resident on the server.
Find the partition holding the file state.tgz and mount it. In my case it was /dev/sdb5 so I used the commands:
# mkdir /mnt/disk
# mount /dev/sdb5 /mnt/disk
# cd /mnt/disk
# ls -al
# cp state.tgz state.tgz.bak
# cd /ramdisk
# mkdir temp
# cd temp
# tar zxf /mnt/disk/state.tgz
# ls -al
# tar zxf local.tgz
# cd etc
# vi shadow

Use the above command to edit the shadow file holding the root password.
Delete all characters between the first and second : character so that you erase the root password.
Write back the shadow file and quit vi using the command :wq
Finally put everything back using the commands:
# cd ..
# rm -rf local.tgz
# tar zcf local.tgz *
# chmod 755 local.tgz
# rm -rf /mnt/disk/state.tgz
# tar zcf /mnt/disk/state.tgz local.tgz
# ls -al /mnt/disk/
# umount /mnt/disk
# shutdown -r now

No comments:

Post a Comment