+5 votes
342 views
in Setting by (242k points)
reopened
Remote access to a Raspberry Pi with SSH: how to enable it

1 Answer

+3 votes
by (1.6m points)
edited
 
Best answer

Setting up SSH on a Raspberry Pi: starting point
Tutorial: enable SSH on Raspberry Pi
How to access the SSH server of your Raspberry Pi once activated
Solution 1: create an ssh file in the boot directory of the SD card
Solution 2: enable SSH server on desktop
Solution 3: enable SSH with terminal in raspi-config
Solution 4: start SSH service with systemctl
How to establish an SSH connection to the Raspberry Pi on Linux and macOS
Configure SSH access on Windows with Putty

image

Remote access to a Raspberry Pi with SSH: how to enable it

The Raspberry Pi not only allows you to create, from elementary hardware components, interesting creative projects. The British minicomputer is in great demand as the basis for operating all types of servers (in the cloud, DNS or Minecraft) thanks to its good computing power and low power consumption. Many users rely on remote access with SSH (Secure Shell) to avoid having to connect a keyboard and monitor each time changes to server settings need to be made..

Index
  1. Setting up SSH on a Raspberry Pi: starting point
  2. Tutorial: enable SSH on Raspberry Pi
    1. Solution 1: create an ssh file in the boot directory of the SD card
    2. Solution 2: enable SSH server on desktop
    3. Solution 3: enable SSH with terminal in raspi-config
    4. Solution 4: start SSH service with systemctl
  3. How to access the SSH server of your Raspberry Pi once activated
    1. How to establish an SSH connection to the Raspberry Pi on Linux and macOS
    2. Configure SSH access on Windows with Putty

Setting up SSH on a Raspberry Pi: starting point

In most cases, those who operate a server on a Raspberry Pi rely on the standardized Raspbian as the software base. The newer versions of the Linux distribution for Pi have an SSH service installed by default , necessary to establish encrypted remote connections. However, for security reasons the service is not activated by default, but to take advantage of all the possibilities of remote access it has to be enabled first. Linux and macOS users can easily connect as the terminal includes native support for SSH connections, but Windows users need to download additional software such as PuTTY or WinSCP.

Note

?pi? It is the standard Raspbian profile and always has the same password (? raspberry?). When the SSH service was still enabled by default, any user who could connect to the Raspberry network could connect to the service without any problem, if the credentials were not changed. This was the reason why SSH was disabled in basic settings..

Tutorial: enable SSH on Raspberry Pi

SSH was disabled by default on Raspberries to prevent external access from being too easy. Thus, in order to minimize this risk of inadvertent spoofing, when activating SSH manually you must change the password of the user? Pi? as soon as possible and, in any case, before connecting to the Internet.

Meanwhile, there are four ways to enable SSH on Raspberry Pi:

Solution 1: create an ssh file in the boot directory of the SD card

If you don't have the ability to operate the Raspberry directly from a keyboard and screen, you can try this simple trick: you can access the microSD card on which Raspbian was installed from an external computer and create a file called ssh in the directory Boot. In this case, it is important that you do not use a file extension and that you make sure that it is not added automatically as it often happens in Windows. If you restart the minicomputer, SSH access will be enabled..

Solution 2: enable SSH server on desktop

By connecting the minicomputer to a keyboard, mouse, and monitor, you can also enable SSH on your Raspberry Pi easily using the desktop interface. To do this, open the Start Menu and from the? Preferences? select the? Raspberry Pi Settings ?. In the tab? Interfaces ? You will find the corresponding entry for SSH and the default setting (? off?), which you can reverse here. Then confirm the change by clicking "OK".

Solution 3: enable SSH with terminal in raspi-config

If you have connected the keyboard and screen to your Raspberry, you can also enable SSH access from the terminal. To do this, start the command line and type the following command:

  sudo raspi-config  

In the menu of the configuration tool that will open, first select point 7 (? Advanced options?) And then A4 (? SSH?). The tool will ask you if you want to activate the SSH server , which you must confirm before closing the settings with? Finish ?.

Solution 4: start SSH service with systemctl

As an alternative to raspi-config , you can use the systemctl command line tool to configure SSH on your Raspberry Pi. Just enter the following two commands in the terminal:

  sudo systemctl enable ssh sudo systemctl start ssh  

While the first command will automatically start the SSH server when the minicomputer starts, the second command will start the server in the current session.

How to access the SSH server of your Raspberry Pi once activated

After starting the SSH service on your Raspeberry Pi, the minicomputer is ready for remote access via the network protocol . The procedure to follow will depend on the type of operating system installed on the external computer. The following instructions show how Windows, Linux and macOS users can establish a secure connection and what complications can arise.

How to establish an SSH connection to the Raspberry Pi on Linux and macOS

MacOS and Linux distributions such as Ubuntu or Debian automatically support the connection with the SSH protocol thanks to the standard implementation of the OpenSSH free software. All you have to do is make sure the computer is on the same network as the Raspberry Pi. If this is the case, you only need the IP address to start the connection. There are two ways to find out:

1. If you operate the Raspberry directly from the keyboard and the monitor, use the minicomputer terminal and type the command:

  hostname ?I  

2. If you run the Raspberry in headless mode, look up the address in the device list of your router or use a tool like Nmap on the external computer.

It then tries to establish the SSH connection in the terminal of the Unix device, where the corresponding command is structured as follows:

  ssh Nombredeusuario@direccion-IP  

In the parameter? Username ?, enter the default profile? Pi? or the name of your own profile (in case you have created one). The first time you establish the SSH connection between the Raspberry Pi and the external device you will receive a security / authentication tip . Once you've made a note of it, enter? Yes? at the terminal to continue. Finally, enter the password for the selected user to connect to the Raspberry command line.

Note

The Raspberry Pi may have been assigned an IP address to which the external computer has previously connected (even if it has connected on another network). In this case, you will receive a warning when establishing the connection, including a request to remove the corresponding IP entry from the list of known devices . Follow the instructions given before running the SSH command again.

Configure SSH access on Windows with Putty

Unlike most Unix-like systems, Windows does not have an SSH client by default. The first step, therefore, will be to download the corresponding application . We have decided on PuTTY but, as client programs of this type are very similar in their handling and functionality, you can use different software if you prefer.

On the main page of the PuTTY project you can download the installation package or the program exe file ( putty.exe ). The latter makes the installation process unnecessary, so PuTTY can start immediately . If you have started the client by double clicking, you only have to enter the host name in the corresponding field and press the "Open" button.

Note

In some cases it is necessary to specify the IP address instead of the host name . If you don't know them, you can use the methods listed above (Nmap, router device list, terminal check).

PuTTTY will then show you a message asking you to confirm the reliability of the Raspberry Pi's SSH server and the SSH key, and you do so by selecting? Yes ?. As with Unix systems, this security warning only appears when you connect for the first time. A new window will open with a message that will allow you to remotely log into the Raspberry terminal by entering your credentials.

advice

If when trying to log in there is a Time-out (the timeout due to inactivity times out), it is very likely that the IP address entered does not match the real address of the Raspberry Pi.


...