Home » Reset the sa password in SQL Server on Linux

Reset the sa password in SQL Server on Linux

by Vlad Drumea
0 comment

This is a brief post containing the steps needed to reset the sa login’s password in SQL Server running on Linux.

Intro

This is pretty useful if you’ve inherited a SQL Server instance running on Linux, but the last person™ didn’t bother saving the sa password in your teams password manager vault, and there is no other sysadmin account on the instance.
Or, if you’re like me, and spin up an occasional test instance on Linux with random passwords for sa that you don’t bother saving anywhere.

Resetting the sa password

Prerequisites

At a minimum, the user doing these steps needs sudo permissions on the following commands and binaries:

  • systemctl stop mssql-server
  • systemctl start mssql-server
  • systemctl status mssql-server
  • /opt/mssql/bin/mssql-conf (this can be restricted even more if your System Admin wants that)

How to

This is where the mssql-conf utility comes to the rescue, and you can use the -h flag to see the help info and pipe it to grep so I can filter only for information pertaining to the word password.

vlad@ubuntu02:~$ sudo /opt/mssql/bin/mssql-conf -h | grep password set-sa-password Set the system administrator (SA) password reset sa password SQL Server Linux

Just so I can be able to confirm the password, I connect with the current sa password.

vlad@ubuntu02:~$ sqlcmd -S localhost -U sa -P Test#Test# -C 1> SELECT @@SERVERNAME; 2> GO ---------------------------------- ubuntu02 (1 rows affected) 1> reset sa password SQL Server Linux

If you’re wondering why I use the -C flag in the above command, check out this blog post.

Before I can reset the password, I have to stop SQL Server.

I then initiate the sa password reset.

I’m prompted for the new password and then to confirm the new password.
For this example I’ll be setting it to 123Test!.

terminal window: vlad@ubuntu02:~$ sudo systemctl stop mssql-server vlad@ubuntu02:~$ sudo /opt/mssql/bin/mssql-conf set-sa-password Enter the SQL Server system administrator password: Confirm the SQL Server system administrator password: Configuring SQL Server... ForceFlush is enabled for this instance. ForceFlush feature is enabled for log durability. Unable to set the system administrator password. Please consult the ERRORLOG in /var/opt/mssql/log for more information. reset sa password SQL Server Linux

Note that there’s a message that states that it was unable to set the administrator password.
This is a known issue in SQL Server 2022 on Linux, but it is a false negative, and the password reset was actually successful.

I then start SQL Server back up.

And validate that it is now running.

Terminal window showing the output of the previous two commands and confirming that SQL Server is running.

Now, to confirm that the password was actually changed.

Terminal window: vlad@ubuntu02:~$ sqlcmd -S localhost -U sa -P 123Test! -C 1> SELECT @@SERVERNAME; 2> GO -------------------------------------------- ubuntu02 (1 rows affected)

Conclusion

If you’re running SQL Server 2022 on Linux, don’t let that false negative error message fool you, the sa password was successfully changed.

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.