Reset SA password on SQL Server on Linux

This article is about how to proceed when you forgot the password of your SQL Server “sa” account, Password was entered wrong many times then “sa” account got locked, or someone wants to reset the password without using SQL Server management studio (GUI).

The mssql-conf is a configuration tool that installs with SQL Server on Linux (Red Hat Enterprise Linux, SUSE Linux Enterprise server, and Ubuntu). This tool as a replacement for SQL Server Configuration Manager which exists on Windows. 

Resets the sa login password 

  • Connect SQL Server using command-line tool with the existing password (The purpose of this step to show you my current “sa” password. At the end, once I reset the “sa” password, you will see that I shall be using a new “sa” password to connect to SQL Server. If you are dealing with real time issue, you can ignore this step.)

sqlcmd -S <SQLInstanceName>-U <UserName> -P <Password>

  • To change the “sa” password, you have to first Stop SQL Server service which is running on the Linux machine. Let’s stop the SQL Server and verify the status of SQL Server. 
sudo systemctl stop mssql-server
sudo systemctl status mssql-server

  • Reset the “sa” password by key new strong password now.
/opt/mssql/bin/mssql-conf set-sa-password
Note: When you are resetting/changing “sa” password using sqlcmd in a bash terminal,  you need to be escaped or not used the character “$” because it is a special character in bash. 
  • Start and verify the status of SQL Server Service
sudo systemctl start mssql-server
sudo systemctl status mssql-server

  • Let’s connect SQL Server with the new password.
sqlcmd -S <SQLInstanceName>-U <UserName> -P <Password>

You have reset “sa” password successfully 🙂 without using GUI option.

Keep Learning and exploring SQL Server on Linux!

4 thoughts on “Reset SA password on SQL Server on Linux

  • Dave

    The first sentence says: “This article is about how to proceed when you forgot the password of your SQL Server “sa” account, Password was entered wrong many times then “sa” account got locked …”

    The first step says: “Connect SQL Server using command-line tool with the existing password …”

    How is it possible to connect with the existing password if it was forgotten or the account is locked?

    Reply
    • Dharmendra

      Thanks Dave for your valuable input! My intension was show the current password and then the new password of the “sa” account. Now, I have modified my wording to make it more clear…..

      Yes, you are right. Once we forgotten or locked the “Sa” account, we cannot connect to SQL Server.

      Reply
  • Alex

    Thanks for this little tutorial. The first screenshot might be more clear if you would show that the “new” password that you will set later is not working at first so People only looking at that screenshot might recognice the error message.
    I almost closed the tab because I just read “Connect SQL Server using command-line tool with the existing Password…”

    Reply
    • Dharmendra

      Thanks Alex for your great feedback! I will modify the blog as per your suggestion.. Thanks again for your valuable feedback!

      Reply

Leave a comment

Your email address will not be published. Required fields are marked *