Kali Raspberry Pi/Headless
From charlesreid1
This is a guide to connecting to a headless installation of Kali Linux on a Raspberry Pi: Kali Raspberry Pi
For general instructions on connecting to a headless Raspberry Pi, visit this page: RaspberryPi/Headless
For info/pages on Kali, visit this page: Kali
Connecting to Kali Pi
Once you've got Kali on the Raspberry Pi, now what? Well, it's pretty easy: once you boot up the Raspberry Pi, it will have a static IP address. The one we picked will let us SSH into the Pi if we have a network cable plugged into our laptop.
That's right: one end of the network cable into the laptop, the other end into the Pi:
Double Check your Pi Version
Although it's best to do this before you wait 30 minutes while your computer flashes an image to an SD card, you should probably check to make sure your Kali Pi image matches your Raspberry Pi version. Version B+ has two USB ports, and Version 2 has four USB ports.
Enabling SSH
Now we come to a question: is SSH enabled by default on Kali Linux builds for the Raspberry Pi?
Some say yes, some say no. I say, sort of.
In my experience, the Kali Linux Raspberry Pi image will start an SSH service, and it will listen on port 22, but you have to wait a while, and give it multiple tries. If at first your connection is refused, wait a little while, and try again.
Ethernet and Power Source
You should note that there may be issues with spotty connectivity if you power the Raspberry Pi from a Mini USB cable. When connected to a Mini USB cable, the Raspberry Pi can't draw enough power, and the Ethernet can sometimes be turned off.
Kali Linux Raspberry Pi: SSH: Connection Refused
This problem drove me nuts. I kept seeing an SSH error, "ssh: connect to host port 22: Connection refused" - even though the Raspberry Pi was up, online, and responding to ping.
$ ssh root@10.0.0.114 ssh: connect to host 10.0.0.114 port 22: Connection refused $ ping 10.0.0.114 PING 10.0.0.114 (10.0.0.114): 56 data bytes 64 bytes from 10.0.0.114: icmp_seq=0 ttl=64 time=6.927 ms 64 bytes from 10.0.0.114: icmp_seq=1 ttl=64 time=6.719 ms 64 bytes from 10.0.0.114: icmp_seq=2 ttl=64 time=1.378 ms 64 bytes from 10.0.0.114: icmp_seq=3 ttl=64 time=8.679 ms
It was independent of how I set up the Pi on the network. Whether it was connected directly to the router, or directly to my computer:
$ ssh root@169.254.113.200 ssh: connect to host 169.254.113.200 port 22: Connection refused $ ping 169.254.113.200 PING 169.254.113.200 (169.254.113.200): 56 data bytes 64 bytes from 169.254.113.200: icmp_seq=0 ttl=64 time=6.927 ms 64 bytes from 169.254.113.200: icmp_seq=1 ttl=64 time=6.719 ms 64 bytes from 169.254.113.200: icmp_seq=2 ttl=64 time=1.378 ms 64 bytes from 169.254.113.200: icmp_seq=3 ttl=64 time=8.679 ms
The headless Kali Raspberry Pi is there, and listening, but refusing our connections.
But then, once, it just magically worked, exactly like it was supposed to:
But I couldn't reproduce it. It was back to failure.
I thought this was a network issue, so I tried different network configurations. No dice.
I thought this was an issue with the SSH service, so I tried tinkering with rc2.d and init.d to verify the sshd service was in fact running at boot time on the headless Raspberry Pi and was listening.
I tried everything. I banged my head against the wall. Then I tried plugging the Raspberry Pi into the wall, instead of plugging it directly into my computer via mini USB cable.
All the SSH problems disappeared into the aether.
The reason? When you plug the Raspberry Pi in via the mini USB cable, it needs more juice than is available, so it starts shutting things off. That means the ethernet port stops listening, and your ability to connect gets really spotty. But it's still listening - so every once and a while, you can SSH into the Raspberry Pi. (That's what makes this issue so hard to debug.)
The take-home: if you're having issues SSHing into your headless Kali Linux Raspberry Pi, don't power your Raspberry Pi via mini USB cable to USB port. Instead, power your Raspberry Pi via USB wall adapter.
An annoying limitation, many hours wasted, but.. ok. At least it's a useful observation about the on-board hardware.
By The Way: Modifying Headless Raspberry Pi Boot Sequence
Part of my struggles in debugging the issue above led me to the rc.d and init.d on the SD card, and modifying the services that start on boot on the headless Raspberry Pi.
Here's how to add and modify startup services and configurations on the Pi:
First load up the SD card and mount it (as described at Kali_Raspberry_Pi/Installing#How_the_Kali_Linux_Startup_SD_Card_Works).
Now you can modify files in the Linux partition, to change what starts up at different runtime levels. Debian Raspberry Pis start in runtime level 2, so anything you want to start up should go in etc/rc2.d.
Actually, what you should do is, put a service script in etc/init.d/myservice, make it executable, then create a symbolic link in etc/rc2.d.
More details here: http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html
By The Way: Modifying Configuration Files on the Raspberry Pi
Note that the above handy trick, editing the Linux partition on the SD card, can also be used to modify configuration files for programs. Want SSH to listen on port 8080? You can edit the etc/ssh/ssh_config file to change the SSH configuration. Want to edit the crontab file? Go for it.
YOU CAN DO... ANYTHING... YOU... WANT!!!
Debugging Headless Raspberry Pi Problems with Logs
I had to waste a lot of time and bang my head in figuring out this SSH problem. But in the process I discovered that (duh!) the headless Raspberry Pi logs everything that's happening. You can modify the startup services or configuration files of the Raspberry Pi, set various logging levels for various programs, boot the headless Raspberry Pi, try and do whatever you're trying to do, and if it doesn't work, you can mount the SD card on your laptop and inspect the log files.