In this video we are going to look at SSH and Python. SSH or Secure Shell is a network protocol that allows administrators to securely connect to a server over an unsecured network. SSH can use public key encryption for authentication and is a great real-world application for the public key encryption videos we did earlier.

This video will also help you understand how SSH works, even if you are not planning to use Python.

SSH is widely used for connecting to Linux or terminal based systems and Again, a lot of the connectivity with SSH can be done with terminal commands and bash scripting, but we are doing to do it with python, which will give us a little more flexibility. SSH is a powerful but with a few lines of python code, you’ll be able to script and automate all ssh has to offer.

So…some background on connectivity with SSH before we start coding…

So, basically how this works is …the client opens a connection to a remote host. The host negotiates the encryption and presents the client with its SSH public key to verify the authenticity of the host. The server then creates an encrypted tunnel with symmetric encryption and something call Diffie Helman.

The user then can authentic to the server with their username and password through this secure tunnel. We will write some python code to automate this step.

But a more secure and easier way to authenticate without passwords is with SSH keys. We modify our code to connect this way as well so you can connect to multiple servers with your python scripts.

For our environment here, I have remote hosts, which is a raspberry pi, and a client which is the terminal window on a mac. To enable ssh on the host or server, you typically type “systemctl enable ssh” and after that, assuming you have a username on the host/server, …we should be all set.

So …to connect and do something useful with ssh in Python, we will use the Paramiko library which I found on Pypi.org. you’ll find some general instructions and demo files here on their github page.

To install SSH, simply use pip3 install paramiko and…. You are all set!

Subscribe: https://www.youtube.com/c/PythonsPracticalSolutionsByPaulMahon/featured

#python

Manage SSH connections with Python for Secure Remote Login
14.30 GEEK