SSH Server Kali

In this post, I’ll share how to install the server ssh on a Kali machine and connect using a key pair from another.

This post is part of a series where I will set up a host with Oracle VirtualBox and automatically backup the VM. Connecting to the VM using ssh will be necessary to turn them off before the backup starts.

Let’s start

Install the server ssh on Kali.

sudo apt-get install ssh

Start the server ssh.

sudo service ssh start

Now test the connection using the ssh command ssh -p <port>. Because of the specific situation where I’m going to connect to the VM from the host, I don’t use the standard port but the port I configured for the NAT on VirtualBox.

I backup the default key as a precaution, but I will not use them to avoid MITM attacks.

mkdir /etc/ssh/default_keys

mv /etc/ssh/ssh_host_* /etc/ssh/default_keys/

After you have moved the default key you have to generate a new pair.

dpkg-reconfigure openssh-server

I verify that the hashes of the new keys differ from the hashes of the default ones. I run the command below from the /etc/ssh folder and /etc/ssh/default_keys

md5sum ssh_host_*

The next step is to edit the SSH server configuration file with the settings you need

nano /etc/ssh/sshd_config

Inside the file modify the two lines below and remove the #.

PasswordAuthentication no

PubkeyAuthentication yes

Now the commands to manage the server’s status, the service has to start at the boot of the VM.

If you only need to start the SSH service temporarily, use ssh.socket:

systemctl start ssh.socket

systemctl stop ssh.socket

To instead permanently enable the SSH service to start whenever the system is booted, use the following:

systemctl enable ssh.service

Then to use SSH immediately without having to reboot use:

systemctl start ssh.service

To check the status of the service, you can use the following:

systemctl status ssh.service

To stop the SSH service, you can use the following:

systemctl stop ssh.service

And to disable the SSH service, so it no longer starts at boot:

systemctl disable ssh.service