Skip to content

Instantly share code, notes, and snippets.

@agustik
Created September 21, 2022 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agustik/29286c317c6be606dce2163ce8fbbdda to your computer and use it in GitHub Desktop.
Save agustik/29286c317c6be606dce2163ce8fbbdda to your computer and use it in GitHub Desktop.
Tempalte prep script for rhel/centos
#!/bin/bash
#SOURCE:http://everything-virtual.com/2016/05/06/creating-a-centos-7-2-vmware-gold-template/
yum update -y
#stop logging services
/sbin/service rsyslog stop
/sbin/service auditd stop
#remove old kernels
/bin/package-cleanup --oldkernels --count=1
#clean yum cache
/usr/bin/yum clean all
#force logrotate to shrink logspace and remove old logs as well as truncate logs
/usr/sbin/logrotate -f /etc/logrotate.conf
/bin/rm -f /var/log/*-???????? /var/log/*.gz
/bin/rm -f /var/log/dmesg.old
/bin/rm -rf /var/log/anaconda
/bin/cat /dev/null > /var/log/audit/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 hardware rules
/bin/rm -f /etc/udev/rules.d/70*
#remove uuid from ifcfg scripts
/bin/sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-ens192
#remove SSH host keys
/bin/rm -f /etc/ssh/*key*
#remove root users shell history
/bin/rm -f ~root/.bash_history
unset HISTFILE
history -c
sys-unconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment