- December 18, 2020
- Posted by: Surender Kumar
- Categories: Kali Linux, Windows and Linux
Setup Kali Linux in Windows 10 WSL2
Table of Contents
This article will explain how you can install Kali Linux directly inside your Windows 10 without having to run the Kali setup. This will save you a lot of time that is required to setup a Kali VM in Windows and you won’t have to go through fixing the errors which can encounter during Kali installation.
Install WSL2 in Windows 10
This article assumes you have already installed WSL2 in your Windows 10. The more information about WSL2 and its installation steps are covered in following article:
https://www.techtutsonline.com/wsl
If you have not installed WSL2, please check this article first and then come back here to start setting up your Kali Linux environment.
Install Kali Linux
- To install Kali Linux (or any other GNU/Linux distribution), open Run dialog (Windows key + R), then type “
ms-windows-store:
” without quotes and hit enter. This will launch Microsoft Store app. - Click on the search, type “Linux” and hit enter. You will see all the popular Linux apps.
-
- Select Kali Linux and click on Install (or Get) button. If it asks you to login with Microsoft account, just click on No, thanks. This will start downloading and installing the Kali Linux which could take a while.
- To launch the Kali linux, click on start and type “Kali” to search.
Tip: The most recently installed app “Kali Linux” will probably be displayed on top of start menu.
- Click on “Kali Linux” and it will display a terminal window with a text “
Installing, this may take a few minutes
”. This will happen only for the first time.
-
- Once done, you will be asked to type a user name and then set a password. After typing password twice, you will be logged in to your Kali Linux environment. This is just a minimal installation of Kali linux. In the next step, we will convert the minimal installation to full including GUI and tools.
-
- The good thing is that your Windows C: drive is automatically mounted to /mnt/c directory in Kali linux. So you can browse and seamlessly transfer the files across Windows and Kali. Take a look at the following image:
- Now that we have a mimimal Kali install running in a terminal. We can run commands in terminal to convert it into full GUI. The
sudo apt update && sudo apt install kali-desktop-xfce -y
command will do that. But instead of installing XFCE desktop environment, we will install Kali Desktop Experience for Windows (aka Win-KeX).
- Now why would we install Win-KeX instead of XFCE which is default desktop environment for Kali Linux? Because “Win-KeX” offers a Kali Desktop Experience for WSL2 which is tightly integrated with Windows. It provides following features:
- Window Mode: Starts a Kali Linux desktop in a dedicated window
- Seamless Mode: Share the Windows desktop between Windows and Kali apps
- Shared clipboard: Allows copy/paste between Windows and Kali Linux apps
- Multi-session support: Supports Root and regular user sessions
- Sound support
Leave the terminal window open and proceed to the next step in order to install Win-KeX.
Install Win-KeX in Kali Linux
- Type the following commands in terminal and hit enter. When prompted, enter the password you set in Step 5.
sudo apt update -y && sudo apt install kali-win-kex -y
It could take a while depending upon the speed of your computer and internet connection. Wait for installation to finish.
Run Win-KeX in Kali Linux
WSL2 allows you to run Win-KeX in three modes.
- Window Mode: Window mode helps keeping the Windows and Kali environments visually apart. Kali linux will run in a dedicated window. To start Win-KeX in Window mode with sound support, type the following command in terminal and hit enter:
win-kex --win -s
- Enhanced Session Mode (ARM only): Enhanced Session Mode runs the Kali Linux desktop session in a separate window using protocols and clients native to Windows. This is supported on ARM devices only. To start Win-KeX in Enhanced Session Mode with sound support, type the following command and hit enter:
win-kex --esm --ip -s
- Seamless mode: Seamless Mode runs a Kali Linux panel on the screen top of the Windows desktop. It removes the visual segregation between linux and window apps which provides a great platform to run a penetration tests in Kali Linux and copy the results straight into a Windows app. To start Win-KeX in Seamless mode with sound support, type the following command and hit enter:
win-kex --sl -s
Now you know How to run Kali Linux in WSL2 without having to install and maintain a VM in VirtualBox or Hyerp-V. But wait a minute; When you want to start Kali Linux, you will have to repeat following two steps every time:
- Open cmd.exe (or PowerShell console) in Windows and then type
wsl -d kali-linux
command - And then type
win-kex --sl -s
command to run WinKex in seamless mode
If you don’t want to repeat these steps every time, proceed to the next step of this article.
Install Windows Terminal
- Open Run dialog (Windows key + R), then type “
ms-windows-store:
” without quotes and hit enter. This will launch Microsoft Store app. - Click on the search, type “Windows Terminal” and hit enter.
-
- Click on Windows Terminal app from search results and click on Install (or Get) button. If it asks you to login with Microsoft account, just click on No, thanks. This will start downloading and installing the Windows Terminal app.
- We will now create a shortcut in Windows Terminal which will help us start the Kali Linux automatically in just a single click.
Now launch Windows Terminal app and press “Ctrl + ,
” keys simultaneously to open terminal settings. It will open “settings.json” file in “Code Writer” app so don’t freak out.
-
- In settings.json file, look for the lines marked with Red box in image, copy the marked section and then paste it right below (as marked by the Green box)
Look at the “commandline” argument’s value. This is the actual command which will run Kali Linux in seamless mode when you click on Windows Terminal shortcut. You can download the kali icon from here.
If you want to run Kali in Window mode, set the “commandline” value to wsl -d kali-linux kex --wtstart -s
. You must slightly change the “guid” value marked with Blue underline otherwise you won’t see the new shortcut in Windows Terminal. You can also change other values if you like and then save the file.
-
- Now close the Windows Terminal and launch it again. Then click on the dropdown icon and choose the Kali Win-KeX option to launch it.
-
- This will launch Kali Win-KeX in seamless mode and you will see a new window running Kali desktop.
That’s it. Now you’re running Kali Linux in Windows 10 in seamless mode where you can change through apps opened in Windows as well as Kali Linux by pressing “Alt + Tab ” or “ Windows logo + Tab ” keys.
If you want to close the Kali window, just close the Kali Win-KeX tab in Windows Terminal.
Tip: Closing the Kali Win-KeX tab in Windows Terminal doesn’t actually terminate the “kali-linux” WSL distribution. You can run wsl -l -v
command in cmd.exe or PowerShell console and you will still see it Running.
To terminate the WSL instance, you need to run wsl -t kali-linux
command manually as shown in image below.
Tip:
See the best WiFi routers supporting monitor mode and packet injection in Kali Linux.
Fixing Errors in Kali Linux
- If you see a message saying Started Win-KeX SL on Windows Terminal but don’t see any Window for Kali Linux, it is most likely that your Windows Firewall or Antivirus Firewall is blocking the application. You need to add the following application to trusted apps list in your Firewall.
\\wsl$\kali-linux\usr\lib\win-kex\VcXsrv\vcxsrv.exe
- If you see an error like Failed to execute child process “dbus-launch” (No such file or directory). You need to connect to Kali linux by running “
wsl -d kali-linux
” command in cmd.exe (or PowerShell console) and then execute the following commands:sudo service xrdp stop sudo apt-get install dbus-x11 sudo service xrdp start