How to Configure Root Password in Ubuntu Cloud Image for VirtualBox and vSphere Deployment


2 views

Modern Ubuntu cloud images (17.10+) use cloud-init for initial configuration instead of traditional passwords. The authentication mechanism differs from standard ISO installations:

# Traditional setup (doesn't apply to cloud images)
sudo passwd root

The correct approach involves modifying cloud-init configuration through these steps:

# First extract the OVA
tar -xvf ubuntu-18.04-server-cloudimg-amd64-custom.ova

# Edit the OVF file to include this cloud-config section
<Property ovf:key="user-data" ovf:type="string">
#cloud-config
password: ubuntu
chpasswd: { expire: False }
ssh_pwauth: True
</Property>

For full SSH access with password authentication:

#cloud-config
users:
  - name: root
    plain_text_passwd: 'ubuntu'
    lock_passwd: false
    ssh_pwauth: true
chpasswd:
  list: |
     root:ubuntu
  expire: false

Follow this sequence for VirtualBox to vSphere migration:

  1. Modify OVA with updated cloud-init config
  2. Test in VirtualBox first using NAT networking
  3. Verify SSH access: ssh root@localhost -p 2222
  4. Export modified VM to vSphere format

If authentication fails, check these logs after boot:

# On the cloud instance
cat /var/log/cloud-init.log
journalctl -u cloud-init

For VirtualBox specifically, ensure port forwarding is configured:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

Modern Ubuntu cloud images (17.10+) no longer come with default passwords due to security hardening. When working with these images in virtualization environments like VirtualBox or vSphere, you'll encounter login issues unless properly configured. Here's how to solve this systematically.

The password property in OVA files doesn't automatically configure the system. Cloud images rely on cloud-init for initial configuration. We need to modify the image to either:

  1. Permanently embed credentials
  2. Properly configure cloud-init to accept OVF properties

For testing purposes, you can directly modify the image:

# Extract OVA
tar -xvf ubuntu-18.04-server-cloudimg-amd64.ova

# Mount the VMDK
sudo apt-get install libguestfs-tools
sudo guestmount -a ubuntu-18.04-server-cloudimg-amd64.vmdk -i /mnt

# Edit shadow file
sudo sed -i 's/root:\*:/root:$6$salt$hashedpassword:/' /mnt/etc/shadow

# Unmount
sudo guestunmount /mnt

For production use, configure cloud-init through these steps:

# Create user-data file
cat > user-data << EOF
#cloud-config
password: ubuntu
chpasswd: { expire: False }
ssh_pwauth: True
users:
  - name: root
    lock_passwd: false
    plain_text_passwd: ubuntu
EOF

# Create meta-data file
touch meta-data

# Generate ISO
genisoimage -output config.iso -volid cidata -joliet -rock user-data meta-data

# Attach ISO to VM

For VirtualBox 5.2.x, use this workflow:

VBoxManage import ubuntu-18.04-server-cloudimg-amd64.ova \
  --vsys 0 --vmname UbuntuCloud \
  --unit 10 --disk "ubuntu-18.04.vmdk"

VBoxManage storagectl UbuntuCloud \
  --name "IDE Controller" --add ide

VBoxManage storageattach UbuntuCloud \
  --storagectl "IDE Controller" \
  --port 0 --device 0 \
  --type dvddrive --medium config.iso

For vSphere deployment, modify the OVF environment properties:

cot edit-properties ubuntu-18.04.ova \
  -p user-data="$(base64 -w0 user-data)" \
  -p meta-data="$(base64 -w0 meta-data)"

To add SSH keys after initial access:

# In user-data
ssh_authorized_keys:
  - ssh-rsa AAAAB3Nz... user@host
  - ssh-ed25519 AAAAC3... user@host

# Or post-deployment
mkdir -p ~/.ssh
echo "ssh-rsa AAAAB3Nz..." >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
  • Check /var/log/cloud-init.log for initialization errors
  • Verify OVF properties are properly passed with vmtoolsd --cmd 'info-get guestinfo.ovfEnv'
  • For VirtualBox, ensure the IDE controller is enabled in VM settings