I have installed MSSQL Server 2017 on Ubuntu 16.04.
Now, I must change password.
I know that I can change password using the following commands:
sudo systemctl stop mssql-server
sudo /opt/mssql/bin/mssql-conf set-sa-password
But! I need to change password via script.
Ok. To solve this problem, I had installed "expect" and had wrote script:
#!/bin/bash
/usr/bin/expect <<EOD
spawn sudo /opt/mssql/bin/mssql-conf set-sa-password
expect "password:"
send "Pa$$wo4d!\r"
expect "password:"
send "Pa$$wo4d!\r"
interact
EOD
Double password - password+confirmation.
I have run the script:
ubuntu:~# bash 1.sh
spawn sudo /opt/mssql/bin/mssql-conf set-sa-password
Enter the SQL Server system administrator password:
Confirm the SQL Server system administrator password:
But it does not work. When I try to connect to mssql server, I got an error:
ubuntu:~# /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P Pa$$wo4d!
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed for user 'SA'..
OK, let's try a Windows authorization:
ubuntu:~# /opt/mssql-tools/bin/sqlcmd -S localhost -E -C
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : SSPI Provider: No
Kerberos credentials available.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Cannot generate SSPI context.
I can't connect to MSSQL Server until I change my password!
And!
I need to change password via script only.
Can somebody help me please?
More easiest way:
sudo MSSQL_SA_PASSWORD=${Password} /opt/mssql/bin/mssql-conf set-sa-password
Solve the problem via script:
#!/usr/bin/python
import pexpect
ssh_cmd = '/opt/mssql/bin/mssql-conf set-sa-password'
timeout=30
child = pexpect.spawn(ssh_cmd, timeout=timeout)
child.expect(['password:'])
child.sendline('Pa$$wo4d!')
child.expect(['password:'])
child.sendline('Pa$$wo4d!')
child.expect(pexpect.EOF)
child.close()
if 0 != child.exitstatus:
raise Exception(stdout)
Related
I have installed Sql Server 2019 Developer Edition and mssql-tools on my Ubuntu 20.04 minimal.
I can connect to my localhost with no issue, but when I want to remote to another sql server:
sqlcmd -S <server> -U <username> -P <password>
I face this error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
I has this issue once in Debian 10, and also search the net for solution, so after that I change my openssl.conf manually (su permission needed):
nano /etc/ssl/openssl.cnf
and add these to my file:
ess_cert_id_alg = sha1 under the [tsa_config1] heading
openssl_conf = default_conf near the top
the following at the end:
[default_conf]
ssl_conf = ssl_sect
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
MinProtocol = TLSv1.0
CipherString = DEFAULT#SECLEVEL=1
I know that MinProtocol and CipherString are normally set to TLSv1.2 and DEFAULT#SECLEVEL=2, but as I mentioned once in my Debian 10, I edited my openssl.conf and change TLSv1.2 to TLSv1.0 and DEFAULT#SECLEVEL=2 to DEFAULT#SECLEVEL=1 and my connection fixed, but in Ubuntu 20.04 minimal not only there wasn't these lines, but also when I insert these manually again I face the same error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
my opnessl version is:
OpenSSL 1.1.1f 31 Mar 2020
I also downgrade my openssl once to 1.0 but it didn't work either!
I couldn't find anything else so I came here to ask for help, appreciate your help.
1.1.1m save my life. Install it manually.
The manual installation looks like:
wget https://www.openssl.org/source/latest.tar.gz -O openssl-1.1.1h.tar.gz
tar -zxvf openssl-1.1.1m.tar.gz
cd openssl-1.1.1m
./config
make
sudo make install
openssl version
sudo ldconfig
Try to add -C option to trust the server certificate:
sqlcmd -S <server> -U <username> -P <password> -C
For more details, please check my answer here: https://stackoverflow.com/a/73443215/970830
I am trying to build a SQL Server container and then run some SQL scripts to add a user and make the schema by using docker build . and later docker-compose build -> docker-compose up
FROM mcr.microsoft.com/mssql/server
COPY all.sql all.sql
COPY auto-setup-db.sql auto-setup-db.sql
RUN /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P myPassword -i auto-setup-db.sql
this line^ fails with:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
The command '/bin/sh -c /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P myPassword -i auto-setup-db.sql' returned a non-zero code: 1
And I'm not sure what I'm doing wrong, does anyone have an idea?
EDIT: this is the relevant part of my docker-compose file:
version: '3'
services:
mssql:
image: mssql
build: ./e2e/mssql
container_name: mssql
environment:
SA_PASSWORD: "myPassword"
ACCEPT_EULA: "Y"
EDIT 2:
Running docker-compose up gives a lot of output from SQL Server ex.
2019-08-29 17:05:13.02 spid8s Starting up database 'tempdb'.
but I need to find a way to run the schema script in there so I thought docker-build would be the easiest place. I'm very new to docker
Trying adding double quotes around the file path and use the full path. Please see the example.
.
.
.
EXPOSE 1433
RUN mkdir -p /var/opt/mssql/database
WORKDIR /var/opt/mssql/database
COPY auto-setup-db.sql .
CMD /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P myPassword -i "/var/opt/mssql/database/auto-setup-db.sql" -o "/var/opt/mssql/database/auto-setup-db.log"
I am having quite a few problems making MSSQL drivers work in Ubuntu. I have followed the following tutorial to make sqlcmd work in Ubuntu 16.04.
# In CMD:
sqlcmd -S my_server_name -U my_username -P my_password -d my_database
1> select name from sys.databases
2> go
After installing the same tool in Ubuntu, it seems to work, but it timeouts when attempting to connect to the same database:
# In Ubuntu bash
sqlcmd -S my_server_name -U my_username -P my_password -d my_database
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2AFA.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
I have tried to change configurations of the database, such that the port is static at 1433, but still no luck.
Do you have any suggestions?
I have fixed the problem!
1. Install MSSQL drivers on Ubuntu
Follow this tutorial.
2. Ensure your port on the database is static
Follow this tutorial to set up a static port.
3. Identify the IP adress of your database
I had to call the following code on the database to get the ip-adress: local_net_address.
SELECT
+ CONNECTIONPROPERTY('net_transport') AS net_transport,
+ CONNECTIONPROPERTY('protocol_type') AS protocol_type,
+ CONNECTIONPROPERTY('auth_scheme') AS auth_scheme,
+ CONNECTIONPROPERTY('local_net_address') AS local_net_address,
+ CONNECTIONPROPERTY('local_tcp_port') AS local_tcp_port,
+ CONNECTIONPROPERTY('client_net_address') AS client_net_address
4. Connect to database (in Ubuntu bash)
Here are two examples with netcat and sqlcmd.
# Using MSSQL tool
sqlcmd -S my_server_ip_adress//my_server_name,my_port -U my_username -P my_password -d my_database
# Using netcat
nc -z -v -w5 my_server_ip_adress my_port
This is my first time trying to setup mssql server under linux server.
This is my error
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed.
The login is from an untrusted domain and cannot be used with
Integrated authentication..
I could login using "sa" and password
Once I use sqlcmd -E -S linuxsqlserver or sqlcmd -S linuxsqlserver I received the error above.
I followed 2 guide in the link
https://www.mssqltips.com/sqlservertip/5075/configure-sql-server-on-linux-to-use-windows-authentication/
https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-active-directory-authentication?view=sql-server-2017
My current system
Ubuntu 18.04
MSSQL
Window Server 2016
AD
What I have done:
join domain (the domain name is Test1)
Creating the Service Principal Name
setspn -a MSSQLSvc/linuxsqlserver.TEST1.COM:1433 sqllinux
Creating the Keytab File for the SQL Server Service
kinit sqllinux#TEST1.COM
kvno MSSQLSvc/linuxsqlserver.TEST1.COM:1433#TEST1.COM (returned 2)
sudo ktutil
addent -password -p MSSQLSvc/linuxsqlserver.Test1.COM:1433#Test1.COM -k 2 -e aes256-cts-hmac-sha1-96
addent -password -p MSSQLSvc/linuxsqlserver.Test1.COM:1433#Test1.COM -k 2 -e rc4-hmac
wkt /var/opt/mssql/secrets/mssql.keytab
quit
Setting up Active Directory Authentication for SQL Server
/opt/mssql/bin/mssql-conf set network.kerberoskeytabfile /var/opt/mssql/secrets/mssql.keytab
systemctl restart mssql-server
Thank you in advance.
I'm trying to connect my local/host machine SQL Server from Laravel vagrant homestead. I've been googling all day trying to connect the host machine's database installing different PHP packages but so far have no lucks. I thought I would remove PHP at this point and try to establish the connection inside homestead using sqlcmd instead.
So, I have installed sqlcmd in homestead and tried to execute the following command to connect to the host machine's database.
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
However, I received the following error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection because an error was encountered during handshakes before login. Common causes include client attempting to connect to an unsupported version of SQL Server, server too busy to accept new connections or a resource limitation (memory or maximum allowed connections) on the server..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection due to prelogin failure.
However, If I use sqlcmd on my host machine and execute the following command, I am able to access the database.
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In my Homestead.yaml, I have set up port forwarding from:
ports:
- send: 1433
to: 1433
You say this doesn't work:
sqlcmd -S 10.0.2.2,1433 -U sa -P 'password' -Q "sp_databases"
Yet this does:
sqlcmd -S LAPTOP-ACQES\MSSQL2017 -U sa -P Asdf1234 -Q "sp_databases"
In the former, you are using the IP, but no instance name.
Try:
sqlcmd -S 10.0.2.2\MSSQL2017 -U sa -P 'password' -Q "sp_databases"
Also:
Ensure TCP/IP is enabled in SQL Network Configuration.
Verify SQL Server Browser is running.
Allow remote connections in SQL Server properties.
Lock SQL Network configuration to port 1433 on all adapters, and disable dynamic ports (then restart services).