How to Use SSH for Remote Management on Raspberry Pi?

In the digital age, Raspberry Pi enthusiasts can leverage their devices to create a wide range of exciting electronic projects. However, interacting with and managing these devices can sometimes pose a challenge. In this regard, SSH (Secure Shell) emerges as a tool that is both simple and powerful, enabling you to easily achieve this goal. It allows you to utilize your Raspberry Pi for controlling electronic components without the need for connecting a keyboard, mouse, or monitor. TechSparks will guide you on effortlessly controlling your SSH into Raspberry Pi in this chapter.

Table of Contents

Enable SSH on Raspberry Pi

Before you can start using SSH to connect to your Raspberry Pi, make sure the SSH service is enabled. The easiest way to do this is by using the ‘Raspi Config’ tool. This tool is a configuration utility on the Raspberry Pi that allows users to easily configure and manage various settings and options. This includes enabling or disabling hardware interfaces like SSH, SPI, I2C, changing the system’s default password, setting the time zone, expanding the file system, and more. With the intuitive interface provided by ‘Raspi Config,’ you don’t need to manually edit configuration files or execute complex commands to make these settings, making configuration easier and more user-friendly.

Here are the steps to enable SSH:

  1. Open the ‘LX Terminal’ terminal window.
  2. Enter the command ‘sudo raspi-config’ to launch ‘Raspi Config.’
  3. In the menu locate ‘SSH,’ press Enter, and then select ‘Enable.’

This will run a script and display a ‘SSH server enable’ dialog, indicating that the SSH functionality has been successfully enabled.”

LX Terminal terminal window

ssh option interface

Select Enable

Prompt message after executing the script

SSH into Raspberry Pi from Mac

If your computer is running the Mac operating system, please open the command line terminal to interact with the computer. You can find the Terminal application in two places: Utilities and Applications. Then, in the terminal window, enter the following command:

				
					ssh 192.168.1.13 -l pi
				
			

It’s important to note that every Raspberry Pi device has its unique IP address used to identify and locate them on the network. So, in the SSH connection command, you need to replace the example IP address (192.168.1.13) with the actual IP address of your Raspberry Pi device. To find the IP address of your Raspberry Pi, you can open a terminal on the Raspberry Pi device and run the following command:

				
					sudo ifconfig
				
			

This command will display network interface configuration information, including the IP address of your Raspberry Pi. You should look for a line that starts with “inet” followed by an IP address. This will be the IP address of your Raspberry Pi.

Change IP

Result after changing IP

In the SSH connection command, the “-l” parameter is used to specify the username to log in to the Raspberry Pi. In this specific command, the username is set to “pi”. When you first attempt to connect to the Raspberry Pi, SSH might display a security warning. This is not an error but rather SSH’s attempt to establish a connection to an unknown host to ensure that you are connecting to the correct device and that communication is encrypted. It will prompt you whether to continue with the connection. If you haven’t changed the password, simply enter “raspberry” for authentication.

Once SSH successfully connects to the Raspberry Pi, the appearance of the command line interface will change. Your local computer’s command prompt may change to the command prompt on the Raspberry Pi, indicating that you have successfully established a remote connection to the Raspberry Pi. It is recommended to confirm this by using the “ls” command, which lists files and folders in the current directory. If successful, you will see a list of the contents of the current directory on the Raspberry Pi.

SSH into Raspberry Pi from Windows

If you want to remotely connect to a Raspberry Pi from a Windows computer, first, ensure that your Raspberry Pi is connected to the same local network. To find the Raspberry Pi’s IP address, open the terminal on the Raspberry Pi and run the following command:

				
					hostname -I
				
			

Remember the displayed IP address for later use in the setup.

Since Windows does not provide an SSH client by default, you’ll need to use third-party tools like PuTTY. Here, we’ll use PuTTY as an example.

Go to the official PuTTY website, select the latest stable version, download it, and run the installer. In the “Host Name” field, enter the Raspberry Pi’s IP address. In the left navigation pane, click on “SSH” to expand the options and ensure that SSH version “2” is selected (which is the case in most situations).

Double-click putty.exe

Click the “Open” button at the bottom of the PuTTY window. This will open a new window prompting you to enter a username. The default username is “pi,” and the default password is “raspberry.” After pressing Enter, PuTTY will attempt to connect to the Raspberry Pi.

pop up warning

Now, you can enter commands in PuTTY just like you would locally on the Raspberry Pi and execute them on the Raspberry Pi.

Correct ssh window

SSH Connection Failures to Raspberry Pi

If you encounter connection issues, you can check the SSH logs for more information. These logs are typically stored in either /var/log/auth.log or /var/log/secure. In many cases, SSH key-related problems are the source of the issue. You can address it with the following commands:

Remove old files:

				
					sudo rm /etc/ssh/ssh_host_*
				
			

Generate new files:

				
					sudo dpkg-reconfigure openssh-server
				
			

Restart the SSH service:

				
					sudo service ssh restart
				
			

If the above steps don’t resolve the issue, you can try updating the software and operating system on your Raspberry Pi:

				
					sudo apt update
sudo apt upgrade
				
			

You Might Be Interested

what is esp32
What is an ESP32

Dive into the world of microcontrollers with TechSparks’ comprehensive guide to the ESP32! Discover the power of this versatile chip, renowned for its integration, low

esp32 ledc
ESP32 LEDC: Precise Control for Diverse Applications

Dive into the world of precise LED control with ESP32’s LEDC module, revolutionizing microcontroller-based PWM technology for versatile applications. Explore the enhanced capabilities, flexible programming

How to Enable Multi-Core on ESP32 Microcontroller
How to Enable Multi-Core on ESP32 Microcontroller

This comprehensive guide elucidates the process of enabling multi-core functionality on the ESP32 microcontroller, leveraging its dual-core architecture for enhanced parallel processing capabilities. Through detailed

Scroll to Top