black electronics

Kali VM Setup & Fixes

Common commands for setting up, updating and fixing a Kali Linux pentesting VM.

A collection of the setup and maintenance commands I end up running on every fresh Kali VM, gathered in one place instead of spread across a dozen bookmarks.

Add the Kali repository (Debian)

Terminal window
echo 'deb http://kali.download/kali kali-rolling main non-free contrib' > /etc/apt/sources.list

If apt complains about a missing or expired signing key:

Terminal window
wget https://archive.kali.org/archive-key.asc -O /etc/apt/trusted.gpg.d/kali-archive-keyring.asc
# or
sudo apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys 7D8D0BF6

Add the Kali repository (Ubuntu)

Ubuntu needs the repository added as its own source file and pinned to a low priority, so Kali packages are only installed when you explicitly ask for them.

Terminal window
sudo apt update && sudo apt upgrade && sudo apt dist-upgrade
sudo apt install curl wget gnupg git
wget -q -O - https://archive.kali.org/archive-key.asc | sudo apt-key add
sudo sh -c "echo 'deb https://http.kali.org/kali kali-rolling main non-free contrib' > /etc/apt/sources.list.d/kali.list"
sudo sh -c "echo 'Package: *' > /etc/apt/preferences.d/kali.pref; echo 'Pin: release a=kali-rolling' >> /etc/apt/preferences.d/kali.pref; echo 'Pin-Priority: 50' >> /etc/apt/preferences.d/kali.pref"
wget http://http.kali.org/kali/pool/main/k/kali-archive-keyring/kali-archive-keyring_2022.1_all.deb
sudo dpkg -i kali-archive-keyring_2022.1_all.deb
rm kali-archive-keyring_2022.1_all.deb
sudo apt update --fix-missing
sudo apt --fix-broken install
sudo apt upgrade

(Adapted from Linux Carnival’s Kali-on-Ubuntu guide.)

Check the Kali version and update

Terminal window
grep VERSION /etc/os-release
uname -v
uname -r
cat /etc/apt/sources.list # Should show the kali-rolling repository
sudo apt update
sudo apt full-upgrade -y

Fix the apt-key deprecation warning (Debian/Ubuntu)

Terminal window
cd /etc/apt
sudo cp trusted.gpg trusted.gpg.d

Increase Kali VM disk space

Terminal window
sudo fdisk -l # Check total disk size and partition sizes
gparted # Right-click the swap partition and select "Swap off", then right-click the extended
# partition and select "Resize/Move" to grow it into the freed space
sudo thunar # Open the file manager as root, if you need it while resizing

See this walkthrough for the full GParted steps.

Remove or change the kernel version

Terminal window
uname -sr # Currently running kernel
dpkg -l | grep linux-image # All installed kernel images
dpkg --get-selections | grep linux-image
sudo apt remove --purge linux-image-6.5.0-kali1-amd64 # Remove a kernel you no longer need
sudo update-grub2

To pin a specific kernel and stop apt from removing it on the next update:

Terminal window
sudo apt-mark hold linux-image-6.3.0-kali1-amd64
sudo apt-mark hold linux-image-amd64
apt-mark showhold # List held packages
sudo apt-mark unhold linux-image-6.3.0-kali1-amd64 # Remove the hold
sudo apt autoremove --purge linux-image-6.3.0-kali1-amd64

Fix a slow “Loading initial ramdisk” boot

Booting should reach this stage in a couple of seconds. If it’s taking much longer, the initramfs image is larger than it needs to be.

Terminal window
sudo nano /etc/initramfs-tools/initramfs.conf # Set MODULES=dep
sudo update-initramfs -u

Package management tricks

Terminal window
sudo apt-get update --fix-missing # Fix repeated 404 errors when installing packages
apt list --installed # List everything installed on the system
sudo apt --purge remove burpsuite # Fully remove a package, including its config
Useful LinksPentest PayloadsCheat Sheets