Learn SSH: Introduction to SSH on Unix-based systems

In this article series, I will explain how to use command line terminal to connect to secure shell (SSH) servers, using the config file for quick access to frequently used servers, and setting up an SSH server on macOS, Ubuntu, or CentOS.

Table of Contents:

Introduction
– SSH CLI Commands
– SSH Config File
– SSH Server Configuration

So, what is SSH and why we use it? SSH is a Transport layer protocol [source]. And, we use SSH to create secure tunnels between two machines, or a client and a server. For instance, we can run a resource-demanding software on a server to speed up our work or deploy our website on it.

To get started, I recommend installing an Ubuntu server or CentOS minimal using Virtualbox on your computer. Then, open the following file with root privileges using your favorite text editor:

/etc/ssh/sshd_config

For instance, we can use vi to open the file:

$sudo vi /etc/ssh/sshd_config

This file is the configuration file for the SSH daemon on your virtual machine. Here, we need to make sure the following line is not commented out using ‘#’ and it is set to ‘yes’:

PasswordAuthentication yes

If we make any changes to this file, we need to restart the ssh service using the following command:

$sudo systemctl restart sshd

Now, we need to find our virtual machine’s IP address (host-only adaptor) to connect to it.

Now, we can open up a terminal on our computer (not inside the virtual machine!) and connect to our virtual machine using the username and password we set during server installation:

$ssh username@virtual_machine_IP_address

In my case, the result looks like this:

$ ssh sina@192.168.56.3
The authenticity of host '192.168.56.3 (192.168.56.3)' can't be established.
ECDSA key fingerprint is SHA256:MyF58hvhnjfyBHdQEl9fkpiGyGMG+b1W2LPfzpUQYu4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.56.3' (ECDSA) to the list of known hosts.
sina@192.168.56.3's password: 
Last login: Mon Aug 12 00:00:00 2019
[sina@localhost ~]$ 

Now, we are successfully connected to the virtual machine using SSH! We can run any command on the virtual machine using the terminal on our local computer.

Next article in the series: SSH CLI Commands

How to install Lapack on Mac OS?

This is a question I get asked a lot. Lapack is actually included in Accelerate library provided by Apple. You can include it in the header file of your C++ source code. Refer to this post for more information on how to use Lapack included in Accelerate.

If you like to use the latest version of Lapack, you can easily install it using Homebrew. Enter the following command in a terminal window to install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

To install Lapack libraries, you should first install GFortran which is included as a part of GCC. Run the following command in a terminal window:

brew install gcc

Now, you can simply install Lapack by typing the following command in a terminal window:

brew install lapack

Please let me know your questions in the comment section.

MS SQL on MacOS: Connect to your database using Python

In this article series, I’ll review the tools and options to connect to an MS SQL server on macOS.

Table of contents:

Microsoft has released a beta version of its ODBC driver for macOS. Here is a quick and easy guide to connecting to your MS SQL using python.

The first thing you need is to install Homebrew.

Enter the following command in a terminal window to install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Afterward, enter following commands in a terminal window to install Microsoft ODBC driver 13 for MacOS:

brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-msodbcsql-preview
brew update
brew install msodbcsql

Next item you need to install is pyodbc by entering following command in a terminal:

pip install pyodbc

or depending on your python installation:

python3 -m pip install pyodbc

Now you have all the prerequisites to connect to your MS SQL database in python.

Now navigate to unixodbc folder using the following command:

cd /usr/local/Cellar/unixodbc/2.3.4

Here you have two files:

1-odbc.ini

2-odbcinst.ini

Open odbc.ini using the following command:

nano odbcinst.ini

There you will see the following information:

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/usr/local/lib/libmsodbcsql.13.dylib
UsageCount=1

You need the copy the content in the square brackets which in my case is “ODBC Driver 13 for SQL Server”.

Exit the editor and open a new file like this:

nano ~/tempfile

Add the following lines to this file:

[MSSQL]
Description = Test to SQLServer
Driver = ODBC Driver 13 for SQL Server
Trace = No
Server = YourSQLServerAddress

Replace “ODBC Driver 13 for SQL Server” with the content you copied in the square brackets. Also, write your SQL server address instead of “YourSQLServerAddress“. Save the file and exit Nano editor.

Now, enter the following command in terminal and enter your password:

sudo odbcinst -i -s -f ~/tempfile -l

To test your connection, open python editor and run the following script:

import pyodbc
a=pyodbc.connect('DSN=MSSQL;UID=yourUserName;PWD=yourPassWord')
print(a)

DSN is the name you used in the temp file. Replace yourUserName and yourPassWord with the ones you use for your SQL server.

You will see an output similar to:

<pyodbc.Connection object at 0xfffffffff>

MS SQL on macOS: Use Oracle SQL manager to access your database

In this article series, I’ll review the tools and options to connect to an MS SQL server on macOS.

Table of contents:

In order to connect to Azure SQL Database from MacOS (OS X) for free, you need two things:

1- Oracle SQL Developer (Download)
2- JTDS driver (Download)

Download these files and install Oracle SQL Developer. Then extract the JTDS driver zip file in a desired location (e.g., \Users\”Your User Name”\JTDS\).

Now open your Oracle SQL Developer and from the menu open preference as following figure shows:

SQL Developer

SQL Developer

From the Preference window, open Database > Third Party JDBC Drivers:

Click on the photo to open the full size image!

SQL Developer

SQL Developer

Here click on Add Entry and find your JTDS folder and choose jtds-1.3.1.jar as the driver path and click on Select and then OK.

Note: Before moving on from this part, make sure you have added your IP address in the firewall setting of your Azure Portal’s desired database.

Now you are ready to add your database to the program. From the connection pane on the left, click on the “+” button.

SQL Developer

SQL Developer

Now click on “SQLServer” tab and add your database connection information:

SQL Developer

SQL Developer

Click on connect. Don’t forget to retrieve your database here. Now save this profile. Now your database is ready to be inquired by transact SQL.

Next article: MS SQL on macOS: Connect to your database using Python