User Tools

Site Tools


systems:ubuntu:clean_up

Systems - Ubuntu - Clean Up

Bash shell script to clean up Ubuntu.

#!/bin/bash
 
# Stop rsyslog to clean up logs.
service rsyslog stop
 
# Cleanup all logs.
cat /dev/null > /var/log/audit/audit.log
cat /dev/null > /var/log/wtmp
cat /dev/null > /var/log/lastlog
 
# Cleanup persistent udev rules.
rm /etc/udev/rules.d/70-persistent-net.rules
 
# Cleanup /tmp directories.
rm -rf /tmp/*
rm -rf /var/tmp/*
 
# Cleanup current ssh keys.
rm -f /etc/ssh/ssh_host_*
sed -i -e 's|exit 0||' /etc/rc.local
sed -i -e 's|.*test -f /etc/ssh/ssh_host_dsa_key.*||' /etc/rc.local
bash -c 'echo "test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server" >> /etc/rc.local'
bash -c 'echo "exit 0" >> /etc/rc.local'
 
# Clear hostname.
cat /dev/null > /etc/hostname
 
# Cleanup apt.
apt-get clean
 
# Cleanup shell history.
history -w
history -c
systems/ubuntu/clean_up.txt · Last modified: 2021/07/23 09:36 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki