Provision a Linux SQL Server virtual machine in the Azure portal

In this quick start tutorial, you use the Azure portal to create a Linux virtual machine with SQL Server 2017 installed.

In this tutorial, you will:


If you don't have an Azure subscription, create a free account before you begin.

Create a Linux VM with SQL Server installed

  1. Sign in to the Azure portal.

  2. In the left pane, click Create a resource.

  3. In the Create a resource pane, click Compute.

  4. Click See all next to the Featured heading.

    See all VM images

  5. In the search box, type SQL Server 2017, and press Enter to start the search.

  6. Click the Filter icon, limit the search to Linux based, Microsoft images, and then click Done.

    Search filter for SQL Server 2017 VM images

  7. Select a SQL Server 2017 Linux image from the search results. This tutorial uses Free SQL Server License: SQL Server 2017 Developer on Red Hat Enterprise Linux 7.4.


    The Developer edition enables you to test or develop with the features of the Enterprise edition but no SQL Server licensing costs. You only pay for the cost of running the Linux VM.

  8. Click Create.

  9. In the Basics window, fill in the details for your Linux VM.

    Basics window


    You have the choice of using an SSH public key or a Password for authentication. SSH is more secure. For instructions on how to generate an SSH key, see Create SSH keys on Linux and Mac for Linux VMs in Azure.

  10. Click OK.

  11. In the Size window, choose a machine size. For more information about VM machine sizes, see Linux VM sizes.

    Choose a VM size


    For development and functional testing, we recommend a VM size of DS2 or higher. For performance testing, use DS13 or higher.

  12. Click Select.

  13. In the Settings window, select the SSH (22) port in the Select public inbound ports list. This is necessary in this quickstart to connect and complete the SQL Server configuration. If you want to remotely connect to SQL Server, also select MS SQL (1433) to open port 1433 for connections over the Internet.

    Inbound ports

  14. You can make changes to other settings or keep the default settings. Then click OK.

  15. On the Summary page, click Purchase to create the VM.

Connect to the Linux VM

If you already use a BASH shell, connect to the Azure VM using the ssh command. In the following command, replace the VM user name and IP address to connect to your Linux VM.

ssh azureadmin@

You can find the IP address of your VM in the Azure portal.

IP address in Azure portal

If you are running on Windows and do not have a BASH shell, you can install an SSH client, such as PuTTY.

  1. Download and install PuTTY.

  2. Run PuTTY.

  3. On the PuTTY configuration screen, enter your VM's public IP address.

  4. Click Open and enter your username and password at the prompts.

For more information about connecting to Linux VMs, see Create a Linux VM on Azure using the Portal.

Change the SA password

The new virtual machine installs SQL Server with a random SA password. You must reset this password before you can connect to SQL Server with the SA login.

  1. After connecting to your Linux VM, open a new command terminal.

  2. Change the SA password with the following commands:

    sudo systemctl stop mssql-server
    sudo /opt/mssql/bin/mssql-conf set-sa-password

    Enter a new SA password and password confirmation when prompted.

  3. Restart the SQL Server service.

    sudo systemctl start mssql-server

Add the tools to your path (optional)

Several SQL Server packages are installed by default, including the SQL Server command-line Tools package. The tools package contains the sqlcmd and bcp tools. For convenience, you can optionally add the tools path, /opt/mssql-tools/bin/, to your PATH environment variable.

  1. Run the following commands to modify the PATH for both login sessions and interactive/non-login sessions:

    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    source ~/.bashrc

Configure for remote connections

If you need to remotely connect to SQL Server on the Azure VM, you must configure an inbound rule on the network security group. The rule allows traffic on the port on which SQL Server listens (default of 1433). The following steps show how to use the Azure portal for this step.


If you selected the inbound port MS SQL (1433) in the settings during provisioning, these changes have been made for you. You can go to the next section on how to configure the firewall.

  1. In the portal, select Virtual machines, and then select your SQL Server VM.

  2. In the list of properties, select Networking.

  3. In the Networking window, click the Add button under Inbound Port Rules.

    Inbound port rules

  4. In the Service list, select MS SQL.

    MS SQL security group rule

  5. Click OK to save the rule for your VM.

Open the firewall on RHEL

This tutorial directed you to create a Red Hat Enterprise Linux (RHEL) VM. If you want to connect remotely to RHEL VMs, you also have to open up port 1433 on the Linux firewall.

  1. Connect to your RHEL VM.

  2. In the BASH shell, run the following commands:

    sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
    sudo firewall-cmd --reload

Next steps

Now that you have a SQL Server 2017 virtual machine in Azure, you can connect locally with sqlcmd to run Transact-SQL queries.

If you configured the Azure VM for remote SQL Server connections, you should also be able to connect remotely. For an example of how to connect remotely to SQL Server on Linux from Windows, see Use SSMS on Windows to connect to SQL Server on Linux. To connect with Visual Studio Code, see Use Visual Studio Code to create and run Transact-SQL scripts for SQL Server

For more general information about SQL Server on Linux, see the Overview of SQL Server 2017 on Linux. For more information about using SQL Server 2017 Linux virtual machines, see Overview of SQL Server 2017 virtual machines on Azure.