Using secure shell (ssh) for login and secure copy (scp) for data transfer on Linux

SSH stands for secure shell. It is an encrypted remote login protocol. Once it has been set up on each node, it can be used to communicate with various other nodes in that network.

The main benefits of SSH are:

  • SSH uses the RSA encryption algorithm to generate public and private keys, making intrusion extremely difficult.
  • Since SSH is a remote login protocol, it can be configured on a laptop. That means you can use your laptop to wirelessly connect to the raspberry pi cluster.
  • Because protocols like SCP (Secure Copy) and SFTP (Secure File Transfer Protocol) run on top of SSH,  you can use them to transfer files and folders directly from one node to another.
  • SSH supports one time log in. This means that you only have to enter credentials the first time you log in. From the second log in onwards, it’s not necessary.

To log in to any other node from the master node use the command:

ssh [email protected]
(change the IP address to represent your IP address) .
This will ask for a password. Once you log in, all the commands you type will run on that node and not on the master.

SSH can also be used to run commands directly on the other nodes. For example, to   change  the hostname of  different nodes, use this command:

ssh [email protected]  ‘sudo echo “cilent001″  | sudo nano /etc/hostname
ssh [email protected]  ‘sudo echo “cilent002″  | sudo nano /etc/hostname
ssh [email protected]  ‘sudo echo “cilent003″  | sudo nano /etc/hostname       …and so on.

 

This way SSH can be used to run commands on other nodes from the master node as:

ssh [email protected]  ‘sudo poweroff’      

 

latest blog pic

This command safely shuts down the node with IP address 192.168.3.216.

The following figure shows how SSH is used to log in to a worker node (192.168.3.216) and from the worker node, get the control terminal back to the master node.

As you can see in the above figure, logging in to a worker node happens directly. But each time the control of the terminal comes back to the master node (192.168.3.215), the login credential has to be entered.

So after issuing commands via SSH to other nodes, there might be situations where data has to be sent to multiple nodes. If the number of nodes are small, then we can manually log in to each node, connect it to a display and keyboard, and send files. But this is a highly inefficient way to do it when the size of the cluster is large.

An easier way would be to use SCP to send files. Install SCP using the command:
sudo apt-get install scp

Read my full post on HowToforge : here 

akshay pai

I am a data science engineer and I love working on machine learning problems. I have experience in computer vision, OCR and NLP. I love writing and sharing my knowledge with others. This is why I created Source Dexter. Here I write about Python, Machine Learning, and Raspberry Pi the most. I also write about technology in general, books and topics related to science. I am also a freelance writer with over 3 years of writing high-quality, SEO optimized content for the web. I have written for startups, websites, and universities all across the globe. Get in Touch! We can discuss more.

One thought on “Using secure shell (ssh) for login and secure copy (scp) for data transfer on Linux

  • January 2, 2015 at 11:37 am
    Permalink

    I had heard about SSH earlier. But today I came to know about it and it’s benefits.

    Reply

Leave a Reply