Linux VMs Clean-up to Create OMIs

This page lists the elements of a Linux virtual machine (VM) you can clean up before creating an OUTSCALE machine image (OMI), especially if you want to share this OMI with other users or to make it public.

An OMI created from a VM or from a snapshot has the same characteristics as this VM or the VM the snapshot is created from. Moreover, a VM can contain sensitive information that you do not want to share.

It is therefore strongly recommended to clean up these elements from your VM, or the VM the snapshot is created from, before creating the OMI.

Overview

This page provides command samples for CentOS 7 VMs, but the list of elements is the same for other Linux VMs.

  • Clean the user information at the very end. To clean the information related to all users, you need to repeat the commands for each user (as explained in the page).

  • After cleaning your VM, it is recommenced to immediately stop it to create the OMI. You can then start it again if you want to keep it, but the cleanup has to be done again if you want to create another OMI.

You must execute these commands as the root user of the VM. To switch to the root user, type: sudo -s

Logs

rsyslog

Prevent creating new logs:

$ service rsyslog stop

Logs

Clean the logs and log history:

$ find /var/log -type f \| while read f; do echo -ne '' > $f; done

Temporary Files

Clean the temporary files on your VM:

$ /bin/rm -Rf /tmp/*
$ /bin/rm -Rf /var/tmp/*

VM Configuration

Route Configuration and Network Map

Clean the route configuration and network map obtained when creating the VM:

$ /bin/rm -f /etc/sysconfig/network-scripts/{ifcfg,route}-eth[1-9]

DHCP Lease

Clean the DHCP lease that is obtained when creating the VM:

$ /bin/rm -f /var/lib/dhclient/dhclient*.lease

NTP Servers

Clean the list of NTP servers that is obtained when creating the VM:

$ sed -i '/dhclient-script/d' /etc/ntp.conf

Creation Information

Clean the information related to the first creation of the VM:

$ /bin/rm -f /var/osc/*

User Password

To check if there is any password, use the following command:

$ cat /etc/shadow

To delete the passwords, use the following command:

$ passwd -d User_Name

User Data

Clean the user data information stored by cloud-init:

$ cloud-init clean

Packages

Clean the packages:

$ yum -y clean all

User

Keypairs

To clean the keypairs of the root user, of the outscale user, and of any other user created in the VM, use the following commands:

$ /bin/rm -f ~/.ssh/authorized_keys
$ /bin/rm -f $HOME/outscale/.ssh/authorized_keys
$ /bin/rm -f $HOME/User_Name/.ssh/authorized_keys

Once you delete the keypairs, you will not be able to reconnect to the VM after you disconnect from it at the end of this procedure.

User Configuration Information

To clean the configuration information of the root user, of the outscale user, and of any other user created in the VM, use the following commands:

$ /bin/rm -f ~/.viminfo
$ /bin/rm -f $HOME/outscale/.viminfo
$ /bin/rm -f $HOME/User_Name/.viminfo

Emails

Clean any emails present on the VM:

$ /bin/rm -f /var/spool/mail/*

User History

To clean the history of the root user, of the outscale user, and of any other user created in the VM, use the following commands:

$ /bin/rm -f ~/.bash_history
$ /bin/rm -f $HOME/outscale/.bash_history
$ /bin/rm -f $HOME/User_Name/.bash_history
$ history -c

Related Pages