- SSH Remote Access Basics and Raspberry Pi OS
- Log in to Raspberry Pi via SSH Using Password
- Use GUI Applications via SSH on Raspberry Pi
This article will introduce several methods of how you can log in to Raspberry Pi using SSH.
SSH Remote Access Basics and Raspberry Pi OS
Secure SHell) is a network protocol that provides secure remote access to another host. Even though we will refer to SSH as software or a tool, it’s important to denote that the term is used as a generic name for the protocol.
In contrast, the actual software used on the given operating system is formally referred to as the implementation of the SSH protocol. Generally, there are multiple implementations of SSH protocol and corresponding utilities that can be installed on the given operating system.
The most commonly used free implementation is the OpenSSH package, and it’s usually part of almost every Linux distribution, including the Raspberry Pi OS.
SSH acts as client-server architecture software, so you’d need to have client packages installed on the system from where you can access Raspberry Pi. On the other hand, Raspberry Pi needs to be running the SSH server, which is installed by default, but you may need to enable it manually.
You can still check if your Raspberry Pi has the SSH installed with the following command, which prints the version of the software package:
If the previous command does not print the valid response starting with the string - OpenSSH_, you must install the needed packages using the next command.
sudo apt install openssh-server
Next, you need to enable the SSH server as it’s usually disabled by default Raspberry Pi OS configuration. The following command will enable the SSH daemon, which is the program that lets you log in:
sudo systemctl start ssh.service && sudo systemctl enable ssh.service
The previous command automatically enables the SSH daemon to be run on system startup. If you would like to investigate if the SSH service is running at the moment, you can utilize the following command.
sudo systemctl status ssh.service
Log in to Raspberry Pi via SSH Using Password
When connecting to a host using SSH, you need to specify the user assumed to exist in the host system. In this case, we assume that the default
pi user exists in the Raspberry Pi OS that we are trying to access. Additionally, we need to know the IP address of the Pi host, which depends on the network it’s located in. You can retrieve the IP address using the following command, but it needs to be executed on the Pi:
Once we know the username and the IP address (e.g., 192.168.0.11), we can insert them in the SSH command and access the host as shown in the following command. Note, though, that commands in this article will be compatible with Unix-based systems such as Linux or Mac OS.
The latter command usually will generate a shell session for the
pi user where you can execute commands remotely as needed. Although, when you connect to a given host for the first time, it shows an authenticity verification prompt where you’d need to provide a
yes reply to continue. Notice that the latter step is done to save the host identification and prevent man-in-the-middle attack to some degree.
Use GUI Applications via SSH on Raspberry Pi
SSH supports X11 forwarding, allowing graphical interface programs to be displayed on a remote system. Even though the feature seems quite powerful, it has some security implications, which is mentioned in the SSH manual, and better to avoid using it unless you fully understand the behavior.
The following SSH command will enable the X11 forwarding and connect to the host. Note that X11 forwarding must usually be enabled on the server-side(Raspberry Pi), but since the default Pi OS configuration includes it enabled, we skip this step in this guide.
ssh -Y email@example.com