How to clean Kali OS

Penthos
4 min readOct 19, 2023

--

I wanted to share some tips and tricks to keep your Kali instance small and speedy!

Introduction

Kali Linux is a powerful penetration testing platform that offers a plethora of tools and utilities for cybersecurity experts. While its rich feature set is its biggest strength, it can also be its downfall when it comes to disk space utilization. Over time, as you install updates, download tools, and generate logs, you may find that your Kali Linux system starts to consume a significant amount of storage space. This could impact not only the performance of your machine but also your productivity as a cybersecurity professional. Regularly cleaning your system is an essential practice to ensure that Kali Linux runs smoothly, allowing you to focus on your security tasks without worrying about system lag or crashes.

Challenges users face in the operating system.

  1. Performance Degradation: One of the most immediate challenges is a noticeable slowdown in system performance. Disk I/O operations can become sluggish, affecting everything from boot times to the loading speeds of applications.
  2. Tool Installation and Updates: Kali Linux is known for its comprehensive suite of penetration testing tools. However, these tools and their subsequent updates often require ample disk space. Limited storage could prevent you from installing essential security tools or updating the existing ones, potentially affecting the quality of your work.
  3. Log Management: During penetration testing, logs can be your best friend, providing valuable information for analysis. However, these logs can quickly accumulate and consume large amounts of disk space, making it difficult to keep track of new logs or archive old ones effectively.
  4. Data Storage: Cybersecurity professionals often need to store large datasets, such as packet captures, malware samples, or client data. Insufficient disk space can make it challenging to manage these critical resources.
  5. Virtual Machines and Containers: Many penetration testers use VMs and containers for isolated testing environments. These consume a considerable amount of disk space, and running low on storage could compromise your ability to use these vital resources effectively.
  6. System Stability: Extremely low disk space could even lead to system instability, causing applications to crash or, in the worst-case scenario, making the system unbootable.

How to Clean Kali OS?

Update the System

  • Before making any changes, it’s always a good idea to update the system.
sudo apt update && sudo apt upgrade -y

Clear APT Cache

  • Clean the APT cache as it can consume disk space.
sudo apt clean

Remove Unused Packages

  • Remove the accumulation of unnecessary packages over time.
sudo apt autoremove -y
sudo apt autoclean

Remove Orphaned Packages

  • Orphaned packages are dependencies that remain on the system even after the package that required them has been removed. These can be safely removed to free up space.
sudo apt install deborphan
sudo deborphan | xargs sudo apt-get -y remove --purge

Empty Trash

  • Files in the trash still consume disk space. Emptying the trash can free up space immediately.
rm -rf ~/.local/share/Trash/*

Remove User Cache

  • Cache files for web browsers and other programs can take up a significant amount of space. (take care with this command)
rm -rf ~/.cache/*

Clear System Logs

  • System logs can take up a lot of space over time. Explain how to manually remove or rotate logs.
sudo journalctl --vacuum-time=3d
  • You can edit the “3d” to as long as you need. EG: “7d”

Remove Old Kernels

  • For those who have updated the kernel multiple times, old kernels can take up space.
echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge

Optimize Databases

  • Some applications, like package managers, use databases that can be optimized to reclaim disk space.
sudo updatedb

Cleaning Temporary Files

  • Temporary files can also consume a good amount of disk space.
sudo rm -rf /tmp/*

Locate and Remove Large Files

  • Use commands like du and find to locate large files that might be unnecessary.
sudo du -sh /var/* | sort -rh | head -5

You can also use find with -xdev, xdev will search all mounts on the filesystem

find / -type f -xdev -size +1G 2>/dev/null

Using find, look for the large files. Any you don’t use anymore you can remove or at least backup and remove.

Third-Party Tools

BleachBit

Using a tool called Bleachbit we can save even more space.

To Install bleachbit:

sudo apt install bleachbit

Run the tool and then select the options you want to clean.

Take care here as you could cause interorbital damage to your system. Always perform a backup or save the current VM state of the machine.

Disk Usage Analyzer

For those who prefer a GUI, the Disk Usage Analyzer tool can provide a graphical representation of disk usage, helping to identify large files and directories.

To install:

sudo apt install baobab

To run:

baobab

Bonus Tip!

Archive Old Data

If you have data that is not frequently accessed but is important to keep, consider archiving it using tools like tar and gzip.

tar czvf archive-name.tar.gz /path/to/directory

Conclusion

After completing all the steps above you should have a much-learner Kali system ready to be abused once again! I hope this helps, please share and like to help others to!

--

--

Penthos
Penthos

Responses (1)