1 Nov 2025
SQL Server on Linux
RHEL & CentOS:
- Download repo config file for SQL 2017
- Sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
- Download repo config file for SQL 2019
- Sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo
- Download SQL server installation package for RHEL and automatically runs the installation
- Sudo yum install -y mssql-server
- Configure SQL using default config:
- Sudo /opt/mssql/bin/mssql-conf setup
- Follow the promts to choose your SQL edition and set the sa pwd
- Enable SQL server daemon to start on system boot
- Sudo systemctl enable mssql-server
Ubuntu:
- Import public GPG keys on the local Ubuntu Linux system
- Curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- Add MS SQL server Ubuntu repo to your system
- Sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/mssql-server-2017 xenial main"
- Sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/mssql-server-2019 xenial main"
- Update file system and install SQL
- Sudo apt-get update
- Sudo apt-get install -y mssql-server
- -y parameter tells installer that answer to any question during the installation process is YES
- Run config script with setup parameter to configure SQL using default configuration
- Sudo /opt/mssql/bin/mssql-conf setup
- You can pass different parameters which are called as environment variables
- https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables?view=sql-server-linux-2017
- Sudo MSSQL_PID=Developer ACCEPT_EULA=Y MSSQL_SA_PASSWORD='Password@123' /opt/mssql/bin/mssql-conf setup
Unattended Installation:
- https://docs.microsoft.com/en-ca/sql/linux/sample-unattended-install-redhat?view=sql-server-ver15#sample-script
- Download the MS SQL Red Hat repo config file for SQL 2017
- Download and install SQL server installation packages for RHEL
- Run the /opt/mssql/bin/mssql-conf script with the setup parameter and env. Variables
- Enable SQL daemon to start on system boot
- Commands:
- Sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
- Sudo yum install -y mssql-server
- Sudo MSSQL_PID=Developer ACCEPT_EULA=Y MSSQL_SA_PASSWORD='Password@123' /opt/mssql/bin/mssql-conf setup
- Sudo systemctl enable mssql-server
- Commands for UBUNTU:
- Curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- Sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/ubuntu/16.04/mssql-server-2017 xenial main"
- Sudo apt-get update
- Sudo apt-get install -y mssql-server
- Sudo MSSQL_PID=Developer ACCEPT_EULA=Y MSSQL_SA_PASSWORD='Password@123' /opt/mssql/bin/mssql-conf setup
- Sudo systemctl enable mssql-server
Configuring the Firewall:
- Linux systems use iptables - a rule based firewall that comes pre-installed
- Uses concept of NAT and packet filtering
- Default system firewall on RHEL and CentOS7 is FirewallD
- It exposes iptables via an API and offers firewall-cmd for config
- https://firewalld.org/
- Ubuntu uses CLI tool UFW (uncomplicated firewall)
- https://help.ubuntu.com/community/UFW
- Configuring on CentOS:
- Sudo systemctl status firewalld
- Sudo firewall-cmd --zone-public --add-port=1433/tcp --permanent
- Zone describes the trust level for a connection
- Public zone signifies that you do not trust any other computers on the network
- Only incoming traffic to TCP port 1433 will be allowed
- Permanent parameter means the rule will be added on a permanent basis
- Sudo firewall-cmd --reload
- To take the change in effect
- Sudo firewall-cmd --list-ports
- Sudo firewall-cmd --list services
- Sudo iptables -nL | grep 1433
- Configuring F/W on Ubuntu:
- Sudo systemctl status ufw
- Sudo ufw status
- Sudo ufw --force enable
- UFW once enabled will block everything including SSH on port 22.
- Sudo ufw allow 22/tcp
- Sudo ufw allow 1433/tcp
Configuring SQL Server on Linux
- Man mssql-conf
- Sudo /opt/mssql/bin/mssql-conf list
- Enabling SQL server Agent:
- Sudo /opt/mssql/bin/mssql-conf set sqlagent.enabled true
- Configuring Default Data & Log directory:
- Default dir is /var/opt/mssql/data
- Sudo mkdir /tmp/dbdata
- Sudo chown mssql /tmp/dbdata
- Sudo chgrp mssql /tmp/dbdata
- Sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /tmp/dbdata
- Sudo /opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /tmp/dbdata
- Configuring default backup directory:
- Default dir is /var/opt/mssql/data
- Sudo mkdir /tmp/dbbackup
- Sudo chown mssql /tmp/dbbackup
- Sudo chgrp mssql /tmp/dbbackup
- Sudo /opt/mssql/bin/mssql-conf set filelocation.defaultbackupdir /tmp/dbbackup
- Enabling Trace flags:
- Sudo /opt/mssql/bin/mssql-conf set traceflag 3226 on
- This TF supresses every successful backup entry in SQL error logs and in system event log
- As all these settings require SQL restart in order to come into effect
- Sudo systemctl restart mssql-server
- Viewing Instance level config settings:
- Cat /var/opt/mssql/mssql.conf
Connect SQL via SSMS remotely:
sudo ufw --force enable
sudo ufw allow 22/tcp
sudo ufw allow 1433/tcp
If an Azure VM: