Installing MS SQL Server on KALI LINUX

Godstrump George
3 min readJan 24, 2021

If you are a windows user who is porting to Linux for the first time, getting around it will be difficult. First thing you will notice is that the command line tool or terminal play an important role in almost everything including installing software and whatnot. While Kali Linux is an operating system for penetration-testing, it does not stop you from carrying out other project with it, like project that require Microsoft SQL Server.

Installing Microsoft SQL Server

A lot this can be found in:

However, some part still get confusing. Hence, that is what this page is for

  1. Import a public repository GPG key
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

2. Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019:

2.1 For Ubuntu 18.04:

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"

3. Run the following command to install MSSQL

sudo apt-get update
sudo apt-get install -y mssql-server

4. After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition. Choose, any free edition from the list, I recommend the “Developer Edition”. Then make sure to specify a strong password.

sudo /opt/mssql/bin/mssql-conf setup

5. Once the service is done, verify that the service is running

systemctl status mssql-server --no-pager

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server. The following steps install the SQL Server command-line tools: sqlcmd and bcp.

Use the following steps to install the mssql-tools on Ubuntu.

  1. Import the public repository GPG keys. Make sure you have curl installed.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

2. Register the Microsoft Ubuntu repository.

For Ubuntu 20.04. If you’ve been following the link I pasted above. You will notice that there is no 20.04 at the time of writing this article but if there is good for you else use the code below and not the one from link.

curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
License terms

3. Update the sources list and run the installation command with the unixODBC developer package.

sudo apt-get update 
sudo apt-get install mssql-tools unixodbc-dev

4. Optional: Add this to your PATH environment variable in a bash shell. This is another tricky and confusing part. Do not use the script from the link posted above. Just run this and it will do the trick.

sudo ln -s /opt/mssql-tools/bin/* /usr/local/bin/

Connect Locally

  1. Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup
sqlcmd -S localhost -U SA -P '<YourPassword>'

If successful, you should get to a sqlcmd command prompt: 1>.

Create a new database

The following steps create a new database named TestDB.

  1. From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

PS: Most of the information here can be found online. Hence, it took multiple online sources to be able to achieve this installation. This post is here to prevent you from going through the same stress as I did during my own installation.

--

--