Skip to content

Instantly share code, notes, and snippets.

@mpslanker
Last active August 5, 2018 21:26
Show Gist options
  • Save mpslanker/13605aa2925d87cb803ca1894b354d38 to your computer and use it in GitHub Desktop.
Save mpslanker/13605aa2925d87cb803ca1894b354d38 to your computer and use it in GitHub Desktop.
# CentOS 7 Template Prep
# Taken from here:
# https://community.spiceworks.com/how_to/151558-create-a-rhel-centos-6-7-template-for-vmware-vsphere
# Update everything but skip broken
yum update --skip-broken -y
# Stop logging services
/sbin/service rsyslog stop
/sbin/service auditd stop
# Remove old kernels
# Ensure the yum-utils is installed
yum install yum-utils -y
package-cleanup --oldkernels --count=1
# Clean up yum
yum clean all
rm -rf /var/cache/yum
# Force log rotation
/usr/sbin/logrotate -f /etc/logrotate.conf
# Clean up old logs
/bin/rm -f /var/log/*-???????? /var/log/*.gz
/bin/rm -f /var/log/dmesg.old
/bin/rm -rf /var/log/anaconda
# Truncate audit logs (keep placeholder)
/bin/cat /dev/null > /var/log/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby
# Remove UDEV persistence
# /bin/rm -f /etc/udev/rules.d/70*
# Remove template MAC and UUIDs
/bin/sed -i ‘/^(HWADDR|UUID)=/d’ /etc/sysconfig/network-scripts/ifcfg-e*
# Clean out /tmp
/bin/rm -rf /tmp/*
/bin/rm -rf /var/tmp/*
# Remove SSH host keys
/bin/rm -f /etc/ssh/*key*
# Remove root user's shell history
/bin/rm -r ~root/.bash_history
unset HISTFILE
# Remove root user's SSH history, etc.
/bin/rm -rf ~root/.ssh/
/bin/rm -rf ~root/anaconda-ks.cfg
# Clear bash history and shutdown for template creation
history -c
sys-unconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment