Mastering Remote Control: Unlocking the Power of SSH with Raspberry Pi

Mastering Remote Control: Unlocking the Power of SSH with Raspberry Pi

February 2, 2024

Dingtalk_20240202175801.jpg__PID:c9abb09d-4c1a-4dbf-853b-62777c737f37

What is SSH?

How can we utilize SSH to connect, monitor, and perform additional tasks on a Raspberry Pi?

SSH (Secure Shell) is a secure protocol widely utilized as the primary method for connecting to your Raspberry Pi. It establishes a text-based interface by creating a remote shell. Once connected, any commands you enter in your local terminal are transmitted to the remote Raspberry Pi and executed there.

This secure and encrypted protocol, abbreviated as SSH, ensures a safe method for executing commands, implementing changes, and configuring services remotely. When initiating an SSH connection, you log in using an account existing on the remote Raspberry Pi.

Benefices

Efficient Remote Access: SSH (Secure Shell) provides an efficient means of remotely accessing Raspberry Pi devices without the need for physical presence.

Increased Productivity: By utilizing SSH, users can access their Raspberry Pi OS from anywhere, allowing for quick and easy completion of administrative tasks. This contributes to significant time savings and increased productivity.

Multitasking Capabilities: SSH offers features like the ability to connect to multiple Raspberry Pi devices simultaneously, enhancing the efficiency of managing multiple devices.

Batch Command Execution: SSH allows the execution of commands in batches, providing a convenient way to automate and streamline tasks on the Raspberry Pi.

Security Features: SSH employs a high level of security through encrypted connections, safeguarding data transferred between local computers and Raspberry Pi devices against unauthorized access. Authentication mechanisms, such as passwords or public keys, add an extra layer of security.

Port Forwarding for Enhanced Security: The capability of port forwarding in SSH improves security by enabling users to establish secure connections to remote services on the Raspberry Pi without exposing them directly to the Internet, minimizing the risk of potential attacks.

Ease of Configuration: Configuring SSH for Raspberry Pi is made easier with tools like Raspberry Pi Imager, where SSH can be enabled before the initial boot.

Diverse Client Compatibility: SSH supports various clients, and in the example provided, Putty for Windows is mentioned. This diversity allows users to choose the SSH client that best suits their preferences and operating system.

Enable SSH

You’ll first need to ensure SSH is enabled. For security reasons, this feature is disabled by default in Raspberry Pi OS. There are several ways to enable SSH on Raspberry Pi OS, either before its installation or after it.

Installation

When using Raspberry Pi Imager for Windows, we can enable SSH before booting up our Raspberry Pi for the first time.

1.png__PID:f0b7f8d3-5141-40c9-8abb-eda8772816c4

1.Select your Raspberry Pi Device

2.Select your OS version

3.Select your Storage

4.Click on Edite Settings

5.Enable SSH with password authentication

6.Save

2.png__PID:b7f8d351-4130-490a-bbed-a8772816c448

Terminal

Open the LXTerminal:
1.Run sudo raspi-config

3.png__PID:f8d35141-30c9-4abb-ada8-772816c44857

2.Select Interfaces option

4.png__PID:d3514130-c90a-4bed-a877-2816c44857dd

3.Go to I2 SSH

5.png__PID:514130c9-0abb-4da8-b728-16c44857ddab

4.Press “yes” to enable SSH and then “finish”

6.png__PID:4130c90a-bbed-4877-a816-c44857ddab16

Once the SSH interface is enabled, we can connect to our Raspberry Pi using various SSH clients. Below, we provide an example of the configuration for the Putty SSH client on Windows.

PuTTY is software for text-based terminal sessions. The software can be used to establish remote connections via Telnet, Secure Shell, Remote Login and other protocols to a remote station that acts as a server for these protocols and to issue commands via the command line interface.

1.Enter the Host Name with your Raspberry Pi's IP address or hostname.

7.png__PID:30c90abb-eda8-4728-96c4-4857ddab1664

2.Accept the public key

8.png__PID:c90abbed-a877-4816-8448-57ddab1664f7

Utilities

Remote monitoring

Remote monitoring of a Raspberry Pi using SSH and htop involves accessing the Raspberry Pi remotely via SSH and using the htop command-line utility to monitor system resources in real-time.

htop is an interactive process viewer and system monitor for Unix-like operating systems. It provides a dynamic real-time view of system processes, CPU usage, memory usage, and other system information.

9.png__PID:0abbeda8-7728-46c4-8857-ddab1664f7fe

To perform remote monitoring of a Raspberry Pi using SSH and htop, follow these steps:

1.Connect to the Raspberry Pi via SSH

10.png__PID:bbeda877-2816-4448-97dd-ab1664f7feec

2.Install htop (if you already no installed)

11.png__PID:eda87728-16c4-4857-9dab-1664f7feecc8

3.Run htop

12.png__PID:a8772816-c448-47dd-ab16-64f7feecc865

You'll see a color-coded interactive display showing system resource usage.Use htop to monitor various system resources such as CPU usage, memory usage, load average, running processes, and more. You can navigate through the process list, sort processes, and perform actions like killing processes if needed.

Remote file manager

Another utility to use by SSH for monitoring our Raspberry Pi is the Midnight Commander file manager to perform various file and system management tasks.

13.png__PID:772816c4-4857-4dab-9664-f7feecc86518

By utilizing SSH and Midnight Commander, you can remotely manage files and perform system tasks on your Raspberry Pi in a convenient and efficient manner, making it particularly useful for headless setups or when accessing the Raspberry Pi from a different location.

Here's how you can set it up and use it:

1.Connect to the Raspberry Pi via SSH

14.png__PID:2816c448-57dd-4b16-a4f7-feecc8651835

2.Install Midnight Commander (mc):

15.png__PID:16c44857-ddab-4664-b7fe-ecc865183528

3.Run Midnight Commander (mc):

16.png__PID:c44857dd-ab16-44f7-beec-c8651835283e

This will open the Midnight Commander file manager in the terminal window.

Navigate and Manage Files:
Use Midnight Commander to navigate through the file system of the Raspberry Pi, view files and directories, copy, move, delete, and manage files and directories using the built-in file management functions.

Perform System Tasks:
Midnight Commander also allows you to perform various system tasks such as editing files, searching for files, changing file permissions, creating symbolic links, and more on the Raspberry Pi, all from within the terminal interface.

In summary

SSH on Raspberry Pi not only facilitates remote access but also offers a range of features that contribute to efficient management, security, and ease of use.

The Ultimate Guide to Transforming Your Raspberry Pi into a Powerful Router Back to News Ultimate Guide: Craft A Complete Raspberry Pi System Monitor for PC