TSF – Giải pháp IT toàn diện cho doanh nghiệp SMB | HCM

Install SQL server 2022 standard on Ubuntu 22.04

Installing SQL Server 2022 Standard on Ubuntu 22.04 allows you to run enterprise-grade Microsoft database services on a stable Linux environment. This guide walks you through adding Microsoft repositories, installing SQL Server packages, configuring authentication, and enabling remote access.

You will also learn how to install the sqlcmd command-line tool, configure firewall rules, secure your SQL instance by disabling the default sa account, and verify service status properly.

Whether you are a Developer, DBA, or IT Administrator, this tutorial ensures a secure, optimized, and production-ready SQL Server 2022 deployment on Ubuntu 22.04.

By the end of this guide, you will have a fully operational SQL Server 2022 Standard instance running on Linux.


🧱 Step 1: Install mssql-server

Download Microsoft public key and configure repository

Download the public key, convert it from ASCII to GPG format, and write it to the required location:

 
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft-prod.gpg > /dev/null

Re-add the repository with the new key:

 
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/ubuntu/22.04/mssql-server-2022 jammy main" | sudo tee /etc/apt/sources.list.d/mssql-server-2022.list

Install SQL Server

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

After installation, choose the SQL version during setup:

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

Enter key:

 
5

Administrator account:

 
sa / Abc@1234

Check SQL Server service status:

 
systemctl status mssql-server --no-pager

🛠 Step 2: Install sqlcmd (Command Line Tool)

1️⃣ Create key directory (if not available)

 
sudo mkdir -p /etc/apt/keyrings

2️⃣ Download Microsoft key

 
curl -sSL https://packages.microsoft.com/keys/microsoft.asc \ | gpg --dearmor \ | sudo tee /etc/apt/keyrings/microsoft-prod.gpg > /dev/null

3️⃣ Add mssql-tools18 repository (Ubuntu 22.04)

 
echo "deb [arch=amd64,arm64 signed-by=/etc/apt/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" \ | sudo tee /etc/apt/sources.list.d/msprod.list

4️⃣ Update package list

 
sudo apt-get update

5️⃣ Install SQL Server CLI tools

 
sudo apt-get install -y mssql-tools18 unixodbc-dev

Add sqlcmd to PATH for quick access:

 
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrcsource ~/.bashrc

🔐 Step 3: Disable SA and Create New Admin User

Why Microsoft recommends disabling SA

• SA is the default login. Everyone knows this username.
• If SQL Server is exposed to LAN or Internet, attackers only need to guess the password.
• Best practice:

  • Log in using SA once.

  • Create a new admin user (hard-to-guess name).

  • Assign sysadmin role.

  • Disable SA.


Safety Procedure

#1 Login with SA

Because ODBC Driver 18 requires TLS encryption by default, and your server uses a self-signed certificate, you must bypass certificate validation using -C.

 
sqlcmd -S localhost -U SA -P 'Abc@1234' -C

#2 Create new admin user

 
CREATE LOGIN admin_sql WITH PASSWORD = 'Abc@1234'; ALTER SERVER ROLE sysadmin ADD MEMBER admin_sql; GO

#3 Disable SA

 
ALTER LOGIN SA DISABLE; GO exit

🌐 Step 4: Configure Firewall and Remote Access

#1 Enable firewall and open required ports

⚠ In production environments, IP restrictions should be configured.

 
sudo ufw enable sudo ufw allow 1433/tcp sudo ufw allow openssh sudo ufw reload

#2 Check port 1433

By default, SQL Server listens on port 1433.

 
sudo ss -ltnp | grep 1433

If you see:

 
LISTEN 0 1433 ... sqlservr

SQL Server is running correctly.


#3 Allow SQL Server to receive remote connections

By default, SQL Server on Linux binds to 0.0.0.0.

To ensure this:

 
sudo /opt/mssql/bin/mssql-conf set network.ipaddress 0.0.0.0 sudo systemctl restart mssql-server

🎯 Conclusion

You have successfully installed and configured SQL Server 2022 Standard on Ubuntu 22.04.

Your environment now includes:

✅ Microsoft repository configuration
✅ SQL Server 2022 Standard installation
✅ Secure authentication setup
✅ Custom admin account
✅ SA account disabled
✅ Firewall configuration
✅ Remote access enabled
✅ sqlcmd CLI tool installed

Your SQL Server instance is now production-ready and secure for real-world workloads.

See also related articles

P5 – Update UniFi Network Controller on Ubuntu

UniFi – Update UniFi Network Controller on Ubuntu (P5 Step-by-Step Guide) Keeping your UniFi Network Controller up to date is critical for security, stability, and feature compatibility—especially in production environments running on Ubuntu Server. An outdated controller may cause device adoption issues, missing features, or even security vulnerabilities. In this...

Read More

P4 – Set Bandwidth Limit for Each Client on UniFi WiFi

Unifi – P4 Set Bandwidth Limit for Each Client on UniFi WiFi 🔍 Overview In office networks or even advanced home networks with many connected devices, a few clients consuming excessive bandwidth is a very common issue. This often leads to slow, unstable connections and directly impacts critical services such...

Read More

P3 – How to Backup and Restore UniFi Controller v9 (Complete Guide)

🔐 UniFi – How to Backup and Restore UniFi Controller v9 (Complete Guide) 🎯 Backing up UniFi Controller v9 is a critical task to protect your entire UniFi network, including configurations, devices, and site settings.In real-world environments, backups are essential for disaster recovery, hardware replacement, system migration, or unexpected failures....

Read More