Kali Linux

How to Enable SSH in Kali Linux

If you wish to enable SSH on Kali Linux, in this article, you will learn how to do so.

In the mid-90s, telnet spawned a secure successor called the secure shell. This is a protocol to communicate with other computers. There are other protocols where you can log in and perform functions as performed by SSH, but it is not safe because it is not encrypted, so people can hijack your sessions and data. However, SSH encrypts the data through a tunnel so that you can securely log in to a remote machine, transmit files, or safely issue remote commands. SSH is applied in the client-server model to transfer and receive the files. There are two terms involved, here: the SSH server and the SSH client. One system acts as a server and the other acts as a client. A public key and a private key is locally stored on the SSH server and client, respectively. The SSH client will make contact with the SSH server and provide the ID of the key pair it wants to use to prove its identity. The challenge is created by the SSH server, which is encrypted by the public key and sent to the client. The client receives the challenge, decrypts it with the private key, and the original challenge is sent back to the SSH server. After the consultation, a secure connection is established. SSH protocol was invented to replace the tunnel so that you could identify the server you are connected to.

We will now take a look at how to enable SSH in Kali Linux.

Install Kali Linux remote SSH-OpenSSH server

Usually, Kali Linux has an OpenSSH server running on it or installed on it. Once you start this server, you can log in via SSH. So, you do not have to install the server, but if you do find yourself in a situation where you do not have it, then you can follow this simple command to install and enable the remote SSH open server in Kali Linux.

$ sudo apt-get install ssh

$ sudo service ssh start

Note: Enabling the SSH server is quite risky, as anyone who knows your password can break into your machine. Securing your password should be your first priority. If you want your service to run for the whole time, then you may follow the next step.

Enable Kali Linux Remote SSH Service

First, you must remove the run levels by entering the following command.

$ sudo update-rc.d -f ssh remove

The next step is to load SSH defaults.

$ sudo update-rc.d -f ssh defaults

After loading, next, you will check whether the service is running.

$ sudo chkconfig ssh

If you want to see a lot more, then you can install chkconfig, which can be installed by entering the following command code.

$ sudo apt-get install chkconfig

You can run chkconfig by entering the command given below.

$ sudo chkconfig -l ssh


$ sudo chkconfig -l

Change Kali Default SSH Keys to Avoid MITM Attack

Every Kali Linux system installed has a chance of a MITM (Man In The Middle) attack. MITM attacks are usually observed in a client-server environment. A MITM attack occurs when a hacker gets in between these two components. Hackers can take advantage of unencrypted communication through the MITM attack and can listen in on all of your traffic. To avoid MITM attacks, you can follow the below procedure.

The first step is to move Kali SSH keys to a new folder.

$ sudo cd /etc/ssh/

$ kali@kali: /etc/ssh# mkdir default_kali_keys

$ kali@kali: /etc/ssh# mv ssh_host_* default_kali_keys/

The second step is to regenerate the keys by entering the following command.

$ kali@kali: /etc/ssh# dpkg-reconfigure openssh-server


The third step is to verify that the SSH key hashes are different. Enter the following command for verification.

$ kali@kali: /etc/ssh# md5sum ssh_host_*

Now, compare the hashes.

$ kali@kali: /etc/ssh# cd default_kali_keys/

$ kali@kali: /etc/ssh/default_kali_keys# md5sum *

Finally, enter the following command code to restart the SSH.

$ kali@kali: /etc/ssh/default_kali_keys# service ssh restart

Set MOTD with a Nice ASCII

MOTD (Message of the Day) is used to send a common message to all the users. The banner is usually boring, so you can edit the files and add the text of your choice, then save the file.

$ kali@kali:~# vi /etc/motd

$ kali@kali:~# service ssh restart


By changing SSH keys in the middle, you may experience a warning sign. Enter the following command to fix this problem.

$ kali@kali:~# vi /root/.ssh/known_hosts

Delete the line that is causing the troubleshoot and restart the SSH.

Change SSH Server Port for Safety

The port number can be changed by entering the following command.

$ kali@kali: /etc/ssh# cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup

The SSH_config file can be edited further by entering the following command.

$ kali@kali: /etc/ssh# vi /etc/ssh/sshd_config

Now, you can restart the OpenSSH server

$ kali@kali: /etc/ssh# service ssh restart

Use the SSH for the next time you use it.

$ kali@kali:~# ssh username@myhostnaname.com -p 10101

Here, 10101 is the destination port, p stands for port, and the hostname can be IP or FQDN.


The term ‘SSH’ describes a set of rules and guidelines that tells your computer how to send data from one place to the other. The administrators, such as the application owner, administrators responsible for the entire system, or privileged users with higher levels of access mainly use the SSH server. I hope this article helped you with enabling SSH in Kali Linux.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.