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.
1 | sudo /opt/mssql/bin/mssql-conf -h | grep password |
Just so I can be able to confirm the password, I connect with the current sa password.
1 | sqlcmd -S localhost -U sa -P Test#Test# -C |
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.
1 | sudo systemctl stop mssql-server |
I then initiate the sa password reset.
1 | sudo /opt/mssql/bin/mssql-conf set-sa-password |
I’m prompted for the new password and then to confirm the new password.
For this example I’ll be setting it to 123Test!
.
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.
1 | sudo systemctl start mssql-server |
And validate that it is now running.
1 | sudo systemctl status mssql-server |
Now, to confirm that the password was actually changed.
1 | sqlcmd -S localhost -U sa -P 123Test! -C |
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.