Setting up Kali Linux on a Raspberry Pi 4

Protovoid
13 min readJan 10, 2021

Introduction

This guide is written for installing Kali Linux on a Raspberry Pi 4 (RP4). I will assume you have some basic knowledge of the Linux command line as well as a Windows computer (which is what I will be using). I may explain processes that seem basic and may skip over those that seem advanced; please either search for what you don’t understand using the internet or leave a question/comment below.

In this guide, please assume that if a command is typed you will need to press the “Enter” key before proceeding. This guide is being written with information taken from both the NullByte and the Lawrence Systems YouTube page. I wrote this as a way to learn and as an update to the Lawrence Systems video on ZeroTier for the Raspberry Pi (as his original guide is now outdated).

Download/Install Kali & Etcher

The first thing that needs to be done (assuming you already have the necessary components to turn on and run a RP4) is to download the Kali Linux img.xz file to your computer. The link below will bring you to the Offensive Security download page; choose the img.xz file that fits the RPi that you have.

Kali Linux:

Image of the download page for kali raspberry pi
Download page for Kali Linux

While you are doing that you will need a program that allows you to flash the img to the SD card. To do that I suggest Etcher. The link below will bring you to the download page. Once downloaded make sure to unpack (unzip) the file using something like winzip or 7zip.

Etcher:

Download page for balenaEtcher

Now for the process of downloading Kali onto an SD card. An 8Gb SD card is required for any basic Kali usage. Insert the SD card into your computer then open up Etcher. From there, click the Flash from File button and choose your Kali Distro. Select your target as the SD card (make sure there is nothing on it, as everything will be deleted). Then click flash, and you’re done.

The Kali Distro should appear as a .img file. If you forgot to extract the Kali Distro, it will appear as a img.xz file, and you should extract it now.

Running the RP4

At this point, if you haven’t already, you will need to assemble your RP4. Follow the instructions from your point of purchase. Once you’re finished assembling your unit, plug in your SD card and turn your RP4 on. Until we set up running headless (see Headless Configuration), you will still need your RP4 connected to a display.

Once you boot up you will be presented with a login screen. Kali comes preset with a user on their RPi and virtual machine images. The username is [kali] and the password is [kali]. Log in and you will be presented with a login screen. Once logged in, open a terminal (black square with a white border at the top left of the screen) to start setting up your RP4.

Basic setup

In the last step, we opened a terminal; now we need to insure your RP4 is secure. The first step has to deal with some basic security. We need to change the password for the user and root. You can do the same password for both, though that may be an issue if someone compromises your user account.

[side note: I don’t suggest changing the username for the base user. If you want to have a specific name create a new user and let that be your base account.]

To begin the process of changing your password, in the terminal type the following:

passwd

You will be asked the current password. As you type nothing will show — the characters you type are hidden. Once finished, press enter and it will then prompt you to put in a new password for the current user. Once that is done type in:

sudo su

You will be prompted to put in a password. Type in the new password you created for the user account. Then, type in:

passwd

Again, you will be prompted like above for a new password. This is for the root account. For windows users this can be considered an administrator account. This is when you can decide to make the user and root account password the same, or to utilize different passwords. Whatever you choose, type that password in now.

Once finished, type in:

exit

This will bring you back to the normal user account in the terminal.

Next go to the top right, where the taskbar is, and connect to your internet. Once you’ve connected let’s update your Kali release (the base operating system of your RP4).

We will be using the https://www.kali.org/docs/general-use/updating-kali/ suggested process on this. You can click on the link or follow below.

We need to first make sure our source.list is correct. In the terminal type:

cd /etc/apt/

Then type:

ls -F

This will show the files in the current folder. Type:

cat /etc/apt/sources.list

This will display the text of the file in the terminal. You should have four lines of text in the file. Two of those lines should begin with deb. If either of the deb lines are prefaced with a # (that means these lines commented out and are not seen by the process when the process is running). So, if either deb line is prefaced with a #, type:

sudo nano /etc/apt/sources.list

This will open a terminal-based text editor. Use your directional arrows to move to the deb line that has # and press Delete on your keyboard to delete the #. Ignore any other lines. Press the CTRL button + x to exit. Press Y to save the file, then press Enter on your keyboard.

Lets go back to your home directory by typing:

cd

Then type:

sudo apt update

This will update your package list which is where most updates are received from.

Once the update finishes, type:

sudo apt full-upgrade -y

This updates your packages and programs on your machine. Use the “-y” argument to force a “yes” anytime you are asked to install something after executing the command. This may take a while and it could have several pop-up messages which need your attention. This will vary by user.

At this point, you have successfully installed Kali Linux onto your RP4, reconfigured the passwords for the user and root accounts, and updated your system to the latest releases.

Changing the SSH Keys

After changing the password and updating the system, we will now be changing the SSH (secure shell) keys. SSH keys on the Kali virtual machine and ARM (what we are using) images are a default set of keys. This means anyone can have the keys to the machine and SSH into it at any time. In order to stop this from happening, we need to do the following:

First, let’s get to where the SSH keys are and see what is in there. Type:

cd /etc/ssh

ls -F

This will show the SSH keys that are listed in the folder. If the file begins with ssh_host_ *anything following* we will need to delete those files and make new keys. To do this, type:

These are the files that we will need to remove. To do this, type:

sudo rm etc/ssh/ssh_host*

By adding the * modifier to the end of the word host, we will be deleting anything that has the beginning filename of ssh_host_. Once that is done we need to create new keys. Luckily this can be completed with one command:

sudo dpkg-reconfigure openssh-server

After that command, you have finished creating new keys.

Persistent IP

In order to access your RP4 using SSH, you must be on the same network. In order to access your RP4 no matter your location, we will set up a Virtual Private Network (VPN) which will give us a static IP address. For this we will be using the service of ZeroTier.

ZeroTier is a free service that allows you to connect devices to a VPN. This device will then have a static IP address. ZeroTier can also be downloaded onto a smartphone or other computer which will allow you to SSH into your RP4. We will set this up so the RP4 automatically connects to ZeroTier on startup.

First, make a ZeroTier account and connect your main device to your new network. Due to the process of making an account and connecting a device to a network, I will not be going over it in this guide (for a how-to, go to https://www.zerotier.com/download/ and follow the steps listed). Once that account is created, you will need to download the ZeroTier file which we will install on the RP4. To download this, go to:

UPDATED (8–14–2022): If the links have not update for a few months go to https://download.zerotier.com/RELEASES/ for the list of releases. Choose the most recent and check which debian version to download. So far the arm64 and armhf styles have not changed for 64bit and 32bit downloads, respectively.

This will download the file and save it to your download folder. This file is downloaded as a .deb file and will need to be installed. For that, we will use the tool gdebi. In the terminal type:

sudo apt install gdebi

Then, press Y to install gdebi.

Once that is installed, go to the location you saved the file using the cd (change directory) command (for an example, please see the screenshot below). To make things easier, you can also use the ls -F command to see the name of the file. You will need the full path to the file (e.g., Sudo gdebi /home/zerotier-one_******.deb [the file shown in the screenshot will be a different name]).

If your terminal title reads (kali@kali)-[/etc/ssh] you will need to type:

cd

This will take you back to your home directory. Then type:

Cd <location of downloaded file>

To see the directory path, type:

pwd

This will output the text of the directory path. Then type:

ls -F

This will show you the files in the current directory. Find the name of the file you downloaded. The full path to file will be the output of pwd. Then add / at the end of the pwd output, followed by the full name of the file (e.g., /home/zerotier-one_1.6.2–2_armel.deb). You will need this for the next command:

sudo gdebi <full path to file>

Then, it may ask for the user password. Then type Y and press Enter.

Now ZeroTier should be installed and running; to check this, type:

sudo zerotier-cli status

You should get a response similar to 200 <information> ONLINE. Now, we have to connect to your ZeroTier network. If you get an error like in the screenshot below, double check that you typed sudo. Next, type:

sudo zerotier-cli join <insert network id>

This should now have you connected to your network. Again, if you get the error as shown in the screenshot above, retype the command with sudo. If you are logged in on the ZeroTier website, your page should refresh and show a new device attached to the network. To allow the device to connect to ZeroTier, you will have to check the box under the “auth” section. Once that is done the page will eventually refresh and show the device as active and it will now have a static IP address.

The last thing to set up for this is auto-joining the network upon startup. To enable this, in the terminal type:

sudo update-rc.d zerotier-one enable

Your terminal may pause for a moment then appear normal, that means this process has been completed. Once this is complete you can restart your RP4 by typing:

sudo shutdown -r now

This will restart your RP4. Check the status of your device on your ZeroTier account page and see if it is still connected once it boots up. Alternatively you can type:

sudo zerotier-cli status

into the terminal and it should show a 200 response and say ONLINE similar to what we saw earlier.

Headless Configuration

The final step in this basic setup is setting up a headless configuration. This is a new requirement in the RP4 (presumably due to the dual HDMI ports). This is a two-step process, as we will need to force the RP4 to turn on if it doesn’t receive as display connection. Second, we will need to turn on auto-login and turn off the sleep function of the unit.

First, to turn off the sleep and hibernation function right click on the battery icon in the top right. This will then show the option to go to the power settings. Change the settings to where it will never sleep or suspend.

Then open a terminal and type:

cd /etc/lightdm

sudo nano lightdm.conf

This will open a terminal-based text editor where we can un-comment two lines under the [Seat:*] heading (you may have to scroll down a bit). Find these two lines using your arrow keys to maneuver (#autologin-user= and #autologin-user-timeout=0). Delete the #’s from the lines. Where it says Autologin-user= type your username against the = (e.g., autologin-user=kali).

Press CRTL + x to exit and press Y, then Enter to save.

Edit (4–18–2021): My RP4 was not working properly, so I reinstalled Kali. However I realized I missed a step when first writing this. The RP4 has two HDMI slots, meaning it checks to see if there is anything connected; if nothing is connected the boot progress will freeze until it detects the HDMI connection. Here’s how to bypass that.

First lets get to the boot menu, type:

cd /boot

once there type:

ls -F

You’re looking for the file named “config.txt”, lets open it and change what we need, type:

nano config.txt

Once you’ve opened the “config.txt” file via the “nano” command, use your arrow keys to go to the section I have highlighted.

You’ll want to remove the “#” on the first “hmdi_force” line, then add the second line only if you have multiple HDMI outputs on your device.

Once that is done press CRTL & x to exit and press Y, then Enter to save.

This is now the time where we see if everything still works. In the terminal type:

sudo shutdown now

This will shut down your RP4 without a wait period (if you don’t add now it will have a 60 second timer prior to turning off). Turn the direct power off and unplug your display cable from the RP4. Once the display cable is unplugged, turn on the RP4 and see if your RP4 reconnects to the ZeroTier network. Alternatively, you can open a SSH program such as PuTTY (or any terminal type application such as Command Prompt) and type:

ssh [user]@[ZeroTier Ip]

In the screenshot below, I used the program PuTTY to log into my own RP4. I find this program the easiest to use while on a windows machine.

If your RP4 connects, you should be prompted to accept the SSH key and type the password to the RP4 user account (because I have previously connected, in the screenshot above, my computer did not ask for the keys). If everything connected, you should have a terminal that is connected to the RP4.

You did it. Congratulations! The cake is a lie.

Please remember, this is just a basic setup and there is still much more work that can be done to add more usability and security to your device. You can check out the following articles for further information:

https://null-byte.wonderhowto.com/how-to/build-beginner-hacking-kit-with-raspberry-pi-3-model-b-0184144/

https://null-byte.wonderhowto.com/how-to/top-10-things-do-after-installing-kali-linux-0186450/

Any comments or suggestions will be extremely helpful! Remember, this is intended for educational purposes only and I do not condone any illegal activities. For more content like this follow my Instagram https://www.instagram.com/protov0id/.

Resources

(don’t use this websites download link, it is out dated) https://www.lawrencesystems.com/how-to-access-a-raspberry-pi-running-kali-linux-anywhere-with-zerotier/

https://zerotier.atlassian.net/wiki/spaces/SD/pages/29065282/Command+Line+Interface+zerotier-cli

--

--