Here i will show you how to set the root password permanently in the image. As an example i will use the following image: http://download.fedoraproject.org/pub/fedora/linux/releases/21/Cloud/Images/i386/Fedora-Cloud-Base-20141203-21.i386.qcow2. This image is cloud-aware image and it is in qcow2 format. You need to install the following: “guestfish” and “libguestfs-tools”:
# yum install guestfish libguestfs-tools
To generate an encrypted password: # openssl passwd -1 Your-Password
I will set the root password as “binan” but you need to choose a strong password:
# openssl passwd -1 binan
Now i will set the generated hash value in the file “/etc/shadow” in the image file. This is done by executing (guestfish –rw -a <image-name>):
# guestfish –rw -a /home/binan/Downloads/Fedora-Cloud-Base-20141203-21.i386.qcow2
><fs> mount /dev/sda1 /
><fs> vi /etc/shadow
Now i will write the hash value of the password ($1$PNq4EoLe$EFwgE1BVdVG3uXqv05Pb5/) in its place:
If the root password in the image file is locked, replace the word “locked” with the generated hash. Now each instance created from this image will have “binan” as root password.
Note: After mounting the file system you can do whatever you want. This is not restricted to the “/etc/shadow” file.
To set different root passwords for different instances, use “cloud-init”.