Install ssh on raspberry pi

Содержание
  1. Подключение по SSH
  2. Включение SSH
  3. Подготовка Raspberry Pi
  4. Поиск IP-адреса Raspberry Pi
  5. Подключение по SSH к консоли Raspberry Pi
  6. Подключение Raspberry Pi к Wi-Fi сети
  7. How to Enable SSH on Raspberry Pi Home » SysAdmin » How to Enable SSH on Raspberry Pi To have a full Raspberry Pi experience, you should use Raspbian, the OS developed exclusively for Raspberry Pi. Raspbian is a Debian-based system optimized to utilize Raspberry Pi hardware most efficiently. If you want to transfer data or administer the device remotely via SSH, you need to enable SSH first. Follow the steps in this guide to learn how to enable SSH on Raspberry Pi without a screen, from the GUI, or using the raspi-config file. We will also show you how to find the IP address of your Raspberry Pi and how to SSH into the device. Raspberry Pi with Raspbian installed Access to a computer with a microSD or SD card reader (for pre-2014 Raspberry Pi versions) Necessary admin permissions to perform the tasks Access to an SSH client: PuTTy in Windows or Terminal in Linux/macOS How to Enable SSH on Raspberry Pi If you installed any of the Raspbian versions from late 2016 onwards, then SSH is disabled by default. The reason behind this decision was to improve security. Since all Raspbian images come with a user “pi” and the default password “raspberry,” it was easy for hackers to use this in their favor. However, you can easily enable SSH on Raspberry Pi even if you do not have a monitor and keyboard connected. We will explain three possible ways to enable SSH on Raspbian. Read through the guide and choose the method that you prefer. Enable SSH on Raspberry Pi in Headless Mode Many users run these devices as a web or media server and configure them via SSH. If you use your Raspberry Pi without a monitor and keyboard, then the only way to enable SSH in headless mode is to use a blank boot file. For this task, you need to create an empty ssh file on another machine. We will use this file on the Raspbian boot SD card to enable SSH. If you do not feel like creating the file yourself, we made the blank ssh boot file available for download. To enable SSH on Raspberry Pi in headless mode, follow these steps: 1. Make sure you properly installed Raspbian on your Raspberry Pi microSD card. If you have already done so, turn off the device and remove the card. 2. Put the microSD card in the card reader of your computer. Wait until the card mounts. You may need to use a microSD to SD card adapter. All recent Raspberry Pi versions use microSD instead of standard-size SD cards. 3. Navigate to the boot folder. This is the root folder of your SD card. Bootis the default volume name when you install a Raspbian system on an SD card. If you are on a Windows machine, use any file manager, such as Explorer. On macOS or Linux, open a terminal window and type: Note that the name of your SD card can be something other than “boot”. If it is, open the root volume folder and proceed with the next steps. 4. In the boot volume, create a file without an extension and name it ssh. On Windows,right-click anywhere in the boot volume’s white space and select New > Text Document. Delete the .txt extension before you hit Enter. If Windows Explorer on your computer does not show file extensions, click View and enable File name extensions in the menu bar. On Mac or Linux,run the touch command while in the boot directory to create a blank ssh file: 5. Safely remove or eject the card from the computer and insert it again in your Raspberry Pi. 6. Boot up Raspberry Pi. Every time you turn on the Pi board, the device looks for the ssh file. When the device finds the file, then SSH is enabled automatically. If you correctly created an empty ssh file without an extension, you can now SSH into your device. Enable SSH on Raspberry Pi using GUI Configuration Options Things get much faster and easier when you have a monitor and peripherals connected to your Raspberry Pi. If you are used to configuring your device using a GUI, follow the steps below. Once your device boots up: 1. Click the raspberry logo at the top-left corner. 2. Select Preferences > Raspberry Pi Configuration. 3. Navigate to the Interfaces tab in the configuration window. 4. Enable SSH in the second line. 5. Click OK to save the changes. That’s it. Your Raspberry Pi is now accessible via SSH. Make sure the device is connected to the internet before trying to establish an SSH session. Enable SSH on Raspberry Pi in the Terminal If you are used to configuring your system from the terminal, you can choose one of the two options below. Enabling SSH with raspi-config To enable SSH using the raspi-config tool: 1. Open the terminal on your Raspberry Pi and run the tool by typing: A BIOS-looking raspi-config tool loads. 2. Use the arrows on your keyboard to select Interfacing Options. 3. Select the P2 SSH option on the list. 4. Select on the “Would you like the SSH server to be enabled?” prompt. 5. Hit Enter on the “The SSH server is enabled” confirmation box. 6. Navigate down and select Finish to close the raspi-config. You can close the terminal window. Your device is now ready to accept SSH connections. Use systemctl to Enable SSH The final option to enable SSH on Raspberry Pi is to start the systemctl service from your terminal. To do so, load the terminal and run these two commands: The ssh service is now both enabled and started. How to SSH Into Raspberry Pi Find IP Address of Raspberry Pi Now that you enabled SSH on your Raspberry Pi, you can use SSH to connect from another machine. Before we can continue, you need to find the IP address of your device. While you are logged in the Raspbian system, open the terminal and run this command: Alternatively, you can run the ifconfig or ip a command to find the IP address. We prefer using the hostname command as it only displays the address without other network information. Use the Terminal in macOS or Linux to Connect to Raspberry Pi Using SSH to remotely manage a Raspberry Pi device is the same as managing any other Linux-based machine. Both macOS and Linux have SSH clients by default. To connect via SSH to your Raspberry Pi from the terminal, use this command: Note: Pi is the default user account. If you use another account name, type it in instead of Pi. Use your device’s IP address identified in the previous step. The first time you connect to your Raspberry Pi, you will get a prompt to accept the RSA key. Type yes, and the new SSH session starts. Use PuTTy in Windows to Connect to Raspberry Pi Windows users can SSH into Raspberry Pi using PuTTY. Start the tool and enter the IP address of your device. Make sure SSH is selected, and the port set to 22. Click Open to start a new session. Enter your Raspberry Pi’s account username and password. Securing Raspberry Pi SSH In November 2016, SSH was disabled by default on Raspbian. This move was made to prevent Raspberry Pi devices from potentially becoming a part of an IoT botnet. Now that you have decided to use SSH to connect to your Raspberry Pi, we advise you to change the default account password. Since all Raspbian installations come with a default account and password, it is easy for hackers to log into your device. To make your device less vulnerable, change Raspberry Pi’s default password. 1. To do so, run the raspi-config tool from the terminal on your device: 2. Select the Change User Password option. Follow the instructions to change the password. Your Raspberry Pi is now ready and more secure for SSH access. We recommend you take further steps to improve SSH security. Note: If you are looking to improve DNS lookup time and connection speed, check out our guide on How To Set Up Raspberry Pi As A DNS Server. Now you know how to enable SSH on Raspberry Pi. This tutorial has shown you how to enable the service even if you do not have a monitor and keyboard connected to your Raspberry Pi. If you have the peripherals connected, then you can choose the method that suits you best. Make sure you take a few basic steps to secure your device. If you need a reminder on the most common SSH commands, refer to our Linux SSH commands guide. Источник How to Enable and Use SSH on Raspberry Pi 4 (Raspberry Pi OS/Raspbian) In this tutorial you’ll learn how to enable ssh on Raspberry Pi 4, with the Raspberry Pi OS (previously Raspbian). On Raspberry Pi OS, ssh is disabled by default, so you’ll have to find a way to enable ssh + find the IP address + connect to it. I will separate the tutorial into 2 parts: Enable ssh if you’re using your Pi with a monitor and keyboard. Enable ssh if you’re using your Pi headless. I’ll also give you some extra configuration steps so everything will run smoothly later on when you work on your Pi via ssh. Using ssh (“Secure Shell”) is one of the best way to work with your Raspberry Pi board(s). It will allow you to work on your Pi remotely, and you can also easily work on multiple boards at the same time from only one computer. Table of Contents First – Flash Raspberry Pi OS (Raspbian) into your micro SD card Before we start, make sure you’ve flashed the Raspberry Pi OS into a micro SD card (class 10, at least 8GB). If you already did that, go to the next step. You are learning how to use Raspberry Pi to build your own projects? Check out Raspberry Pi For Beginners and learn step by step. You can also the Raspberry Pi Imager directly, which will download and flash the image all at once. Alright, now let’s enable ssh on the Pi. New feature: Enable SSH directly when you flash the SD card This is quite convenient: you can directly enable SSH before writing the operating system into the SD card. Note that this only works if you’re starting from scratch, not if you’ve already flashed the OS. In the latter case, skip this part of the tutorial. If you’re starting from scratch, let’s start! So, before writing the operating system on the SD card, click on the “settings” icon. Click on “Enable SSH”, and set a username + password. You will need to remember this username/password for when you will connect to the Raspberry Pi via SSH. Also, scroll down a bit and enable Wi-Fi. Make the Raspberry Pi board connect to the same Wi-Fi network as your laptop/computer. Then, save and click on “write”. Now that you’ve done this step, you can go directly to the “Find the Raspberry Pi’s IP address” part below (either with a monitor/keyboard, or without). You have enable SSH but you still need to find the IP address to be able to connect to the Raspberry Pi. Enable ssh on Raspberry Pi 4 with a monitor and keyboard So, you already have a working operating system on the SD card and don’t want to flash it again? Let’s first see how you can enable ssh on your Raspberry Pi 4, when using an external monitor + keyboard + mouse. Initialization If this is the first time you boot your Pi with your new image, then follow the steps of the “Welcome” screen. You will: Select a country, language, keyboard layout, timezone. Connect to a Wi-Fi network. Change the default password (user: “pi”, password: “raspberry”). Update packages to their newest version. The important thing you need for the following is that the Raspberry Pi 4 (ssh server) is connected to the same Wi-Fi network as your computer (ssh client). Enable ssh from the Raspberry Pi 4 First, open a new terminal. Execute sudo raspi-config . You will see this menu (or something very similar). Select “Interfacing Options” and press ENTER. Then, select “SSH” and press ENTER. Select “Yes”, press ENTER, and you’ll get a message “The SSH server is enabled”. Then, you’ll see the raspi-config menu again, press ESCAPE to quit. Find the Raspberry Pi’s IP address To connect to the Pi from your computer, you’ll need to know the IP address of the Pi. Well, as you’re already working from the Pi, that’s really easy. Simply open a terminal and run hostname -I . This will give you the IP address of the Pi inside the Wi-Fi network it’s connected to. Here in my case: 192.168.43.56. Of course you will certainly have a different value. Connect to the Pi via ssh If you’re using Linux, Mac OS, or Windows 10 (with at least the October 2018 update), you can simply use a ssh client from a terminal. If you’re using a previous version of Windows, you can download and use the Putty software. So, open a new terminal on your computer. In Windows 10, search for “cmd” or “terminal” in the search bar. Then, to be able to create a successful connection, you need 3 things: the IP address of the Pi: well that’s just what we got from the last step. username: this is the username you have on your Pi. The default one with Raspbian is “pi”. (on your Pi, execute whoami to check the username) password: by default this is “raspberry”, but you should already have changed it in a previous step. To create a ssh client and thus connect to the Raspberry Pi 4, execute: ssh username@ip_address , and then provide the password. Great, you’re now connected to the Pi with ssh! Working in this terminal (session) is the same as if you work directly on the Pi (with a monitor + keyboard). Enable ssh on Raspberry Pi 4 without any monitor Here comes a greater challenge: what if you don’t have an extra monitor + keyboard to first enable ssh on your Raspberry Pi 4? Or… What if you’re just too lazy to setup all the hardware? (I know I am) Well, you can enable ssh on your Pi without any monitor, and it’s not that hard. Let’s get started. (note: if you’re willing to flash the SD card again – and loose all data – you can go back in the tutorial and learn how to enable SSH + Wi-Fi directly on the SD card. If not, read on.) Make the Pi automatically connect to Wi-Fi You may directly plug an Ethernet cable between your computer and your Pi, so they’re both already in the same network, but let’s say that we’re not going to use an Ethernet cable here. So, before we can even think of ssh, we first need to make sure the Pi can connect to the Wi-Fi network. Put your micro SD card back into your computer, and navigate into its root folder (named “boot”). Here create a file named “wpa_supplicant.conf” (remove any other extension like “.txt”). Open this file with any text editor (on Windows -> right click + “Open with”), and write the following: Replace WIFI_NETWORK_NAME and WIFI_PASSWORD with the actual name and password of your Wi-Fi network. Save and quit the file. Great, now the Pi should automatically connect to the Wi-Fi network on boot. But, before you remove the SD card, let’s configure ssh. Enable ssh directly on the SD card Here it’s really simple. Still in the root folder of your SD card (“boot”) create a new file named “ssh”, with no extension. That’s it! This will enable ssh when you boot the Pi. Now, remove the micro SD card from your computer, make sure the Pi is powered off, put the SD card into the Pi, and power it on. Find the Raspberry Pi’s IP address As you don’t have a direct access to your Pi, you’ll need to find its IP address from your computer. On Windows, you can download and install Advanced IP Scanner. Open the software and press “Scan”. Here you can see, we have a machine named “raspberrypi” on the network, and we also have its IP address! >> Watch this for a complete tutorial on how to use Advanced IP Scanner: Alternative: if you want a software with a graphical interface that runs on both Windows, Linux, and MacOS, use Angry IP Scanner. If you’re on Linux, you can use the nmap tool ( sudo apt install nmap ). Let’s say the IP address of your computer is 192.168.43.138, then you can execute: And you also find the IP address of the Pi. >> Watch this for a video explanation on how to use nmap: Connect to the Raspberry Pi 4 via ssh Well, now it’s the same as before (when we setup ssh with a monitor). From your computer, open a terminal and execute ssh username@ip_address . Here the username is “pi”, and the password is “raspberry” since we haven’t changed it yet. If you see this line -bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) , there is a problem with the locale setup, and you can fix it by executing those commands: Also, as you can see in the logs, now might be a good time to change the password with passwd . And also update/upgrade your packages: Your Raspberry Pi 4 is now configured and you can continue to work on it via ssh! Conclusion In this tutorial you’ve seen how to enable ssh on Raspberry Pi 4, using the Raspberry Pi OS (previously Raspbian). Sometimes you will want to work with a monitor, sometimes not. And that gives you 2 ways of setting things up. At the end, once your Pi is connected to the Wi-Fi network, and ssh is enabled, well it is the same whether you use a monitor or not. From your computer, you’ll simply open a terminal (from Windows 10/Linux/MacOS), and you’ll ssh into the Pi. You can create multiple clients to open multiple sessions on the Pi. This tutorial was for Raspberry Pi OS (Raspbian), but maybe you’ll also want to try to install Ubuntu on your Pi: here is how to setup ssh when using Ubuntu. Did you find this tutorial useful? Do you want to learn how to build awesome projects with Raspberry Pi? If yes, this course is for you: Did you find this tutorial useful? Do you want to become better at programming robots, with Arduino, Raspberry Pi, or ROS2? If yes, subscribe to receive exclusive content and special offers! Источник
  8. How to Enable SSH on Raspberry Pi
  9. Enable SSH on Raspberry Pi in Headless Mode
  10. Enable SSH on Raspberry Pi using GUI Configuration Options
  11. Enable SSH on Raspberry Pi in the Terminal
  12. Enabling SSH with raspi-config
  13. Use systemctl to Enable SSH
  14. How to SSH Into Raspberry Pi
  15. Find IP Address of Raspberry Pi
  16. Use the Terminal in macOS or Linux to Connect to Raspberry Pi
  17. Use PuTTy in Windows to Connect to Raspberry Pi
  18. Securing Raspberry Pi SSH
  19. How to Enable and Use SSH on Raspberry Pi 4 (Raspberry Pi OS/Raspbian)
  20. First – Flash Raspberry Pi OS (Raspbian) into your micro SD card
  21. New feature: Enable SSH directly when you flash the SD card
  22. Enable ssh on Raspberry Pi 4 with a monitor and keyboard
  23. Initialization
  24. Enable ssh from the Raspberry Pi 4
  25. Find the Raspberry Pi’s IP address
  26. Connect to the Pi via ssh
  27. Enable ssh on Raspberry Pi 4 without any monitor
  28. Make the Pi automatically connect to Wi-Fi
  29. Enable ssh directly on the SD card
  30. Find the Raspberry Pi’s IP address
  31. Connect to the Raspberry Pi 4 via ssh
  32. Conclusion
Читайте также:  Как сделать цветной ксерокс на принтере epson

Подключение по SSH

Работать с Raspberry Pi можно и без монитора — через SSH соединение. Рассмотрим как подключится к микрокомпьютеру из операционной системы Windows.

Включение SSH

Подготовка Raspberry Pi

Если у вас карта памяти без Raspberry Pi OS , запишите образ самостоятельно.

Поиск IP-адреса Raspberry Pi

Для подключения к Raspberry Pi необходимо знать IP-адрес платы в локальной сети.

При динамической адресации (DHCP) маршрутизатор может менять IP-адрес при каждом включении платы. В таком случае вам каждый раз придётся повторять этот шаг.

Подключение по SSH к консоли Raspberry Pi

Raspberry Pi запущена, IP-адрес известен — можно приступать к подключению по SSH.

Скачать PuTTY с официального сайта разработчиков.

При вводе пароля, вводимые символы не отображаются в консоле. Это нормально для *NIX-систем.

$

У вас всё получилось. Теперь можно управлять Raspberry Pi консольными командами Raspbian .

Подключение Raspberry Pi к Wi-Fi сети

и запомните имя интересующей вас точки доступа.

, где YourSSID — имя точки доступа, psk — пароль, key_mgmt — тип шифрования.

Если подключение выполнено успешно, вы увидите информацию о точке доступа.

Источник

How to Enable SSH on Raspberry Pi

Home » SysAdmin » How to Enable SSH on Raspberry Pi

To have a full Raspberry Pi experience, you should use Raspbian, the OS developed exclusively for Raspberry Pi. Raspbian is a Debian-based system optimized to utilize Raspberry Pi hardware most efficiently. If you want to transfer data or administer the device remotely via SSH, you need to enable SSH first.

Follow the steps in this guide to learn how to enable SSH on Raspberry Pi without a screen, from the GUI, or using the raspi-config file. We will also show you how to find the IP address of your Raspberry Pi and how to SSH into the device.

  • Raspberry Pi with Raspbian installed
  • Access to a computer with a microSD or SD card reader (for pre-2014 Raspberry Pi versions)
  • Necessary admin permissions to perform the tasks
  • Access to an SSH client: PuTTy in Windows or Terminal in Linux/macOS

How to Enable SSH on Raspberry Pi

If you installed any of the Raspbian versions from late 2016 onwards, then SSH is disabled by default. The reason behind this decision was to improve security. Since all Raspbian images come with a user “pi” and the default password “raspberry,” it was easy for hackers to use this in their favor.

However, you can easily enable SSH on Raspberry Pi even if you do not have a monitor and keyboard connected. We will explain three possible ways to enable SSH on Raspbian. Read through the guide and choose the method that you prefer.

Enable SSH on Raspberry Pi in Headless Mode

Many users run these devices as a web or media server and configure them via SSH. If you use your Raspberry Pi without a monitor and keyboard, then the only way to enable SSH in headless mode is to use a blank boot file.

For this task, you need to create an empty ssh file on another machine. We will use this file on the Raspbian boot SD card to enable SSH. If you do not feel like creating the file yourself, we made the blank ssh boot file available for download.

To enable SSH on Raspberry Pi in headless mode, follow these steps:

1. Make sure you properly installed Raspbian on your Raspberry Pi microSD card. If you have already done so, turn off the device and remove the card.

2. Put the microSD card in the card reader of your computer. Wait until the card mounts. You may need to use a microSD to SD card adapter. All recent Raspberry Pi versions use microSD instead of standard-size SD cards.

3. Navigate to the boot folder. This is the root folder of your SD card. Boot is the default volume name when you install a Raspbian system on an SD card. If you are on a Windows machine, use any file manager, such as Explorer. On macOS or Linux, open a terminal window and type:

Note that the name of your SD card can be something other than “boot”. If it is, open the root volume folder and proceed with the next steps.

4. In the boot volume, create a file without an extension and name it ssh.

  • On Windows,right-click anywhere in the boot volume’s white space and select New > Text Document. Delete the .txt extension before you hit Enter. If Windows Explorer on your computer does not show file extensions, click View and enable File name extensions in the menu bar.
  • On Mac or Linux,run the touch command while in the boot directory to create a blank ssh file:

5. Safely remove or eject the card from the computer and insert it again in your Raspberry Pi.

6. Boot up Raspberry Pi.

Every time you turn on the Pi board, the device looks for the ssh file. When the device finds the file, then SSH is enabled automatically. If you correctly created an empty ssh file without an extension, you can now SSH into your device.

Enable SSH on Raspberry Pi using GUI Configuration Options

Things get much faster and easier when you have a monitor and peripherals connected to your Raspberry Pi. If you are used to configuring your device using a GUI, follow the steps below.

Once your device boots up:

1. Click the raspberry logo at the top-left corner.

2. Select Preferences > Raspberry Pi Configuration.

3. Navigate to the Interfaces tab in the configuration window.

4. Enable SSH in the second line.

5. Click OK to save the changes.

That’s it. Your Raspberry Pi is now accessible via SSH. Make sure the device is connected to the internet before trying to establish an SSH session.

Enable SSH on Raspberry Pi in the Terminal

If you are used to configuring your system from the terminal, you can choose one of the two options below.

Enabling SSH with raspi-config

To enable SSH using the raspi-config tool:

1. Open the terminal on your Raspberry Pi and run the tool by typing:

A BIOS-looking raspi-config tool loads.

2. Use the arrows on your keyboard to select Interfacing Options.

3. Select the P2 SSH option on the list.

4. Select on the “Would you like the SSH server to be enabled?” prompt.

5. Hit Enter on the “The SSH server is enabled” confirmation box.

6. Navigate down and select Finish to close the raspi-config.

You can close the terminal window. Your device is now ready to accept SSH connections.

Use systemctl to Enable SSH

The final option to enable SSH on Raspberry Pi is to start the systemctl service from your terminal.

To do so, load the terminal and run these two commands:

The ssh service is now both enabled and started.

How to SSH Into Raspberry Pi

Find IP Address of Raspberry Pi

Now that you enabled SSH on your Raspberry Pi, you can use SSH to connect from another machine.

Before we can continue, you need to find the IP address of your device. While you are logged in the Raspbian system, open the terminal and run this command:

Alternatively, you can run the ifconfig or ip a command to find the IP address. We prefer using the hostname command as it only displays the address without other network information.

Use the Terminal in macOS or Linux to Connect to Raspberry Pi

Using SSH to remotely manage a Raspberry Pi device is the same as managing any other Linux-based machine. Both macOS and Linux have SSH clients by default.

To connect via SSH to your Raspberry Pi from the terminal, use this command:

Note: Pi is the default user account. If you use another account name, type it in instead of Pi. Use your device’s IP address identified in the previous step.

The first time you connect to your Raspberry Pi, you will get a prompt to accept the RSA key. Type yes, and the new SSH session starts.

Use PuTTy in Windows to Connect to Raspberry Pi

Windows users can SSH into Raspberry Pi using PuTTY.

Start the tool and enter the IP address of your device. Make sure SSH is selected, and the port set to 22.

Click Open to start a new session. Enter your Raspberry Pi’s account username and password.

Securing Raspberry Pi SSH

In November 2016, SSH was disabled by default on Raspbian. This move was made to prevent Raspberry Pi devices from potentially becoming a part of an IoT botnet.

Now that you have decided to use SSH to connect to your Raspberry Pi, we advise you to change the default account password.

Since all Raspbian installations come with a default account and password, it is easy for hackers to log into your device. To make your device less vulnerable, change Raspberry Pi’s default password.

1. To do so, run the raspi-config tool from the terminal on your device:

2. Select the Change User Password option.

Follow the instructions to change the password. Your Raspberry Pi is now ready and more secure for SSH access. We recommend you take further steps to improve SSH security.

Note: If you are looking to improve DNS lookup time and connection speed, check out our guide on How To Set Up Raspberry Pi As A DNS Server.

Now you know how to enable SSH on Raspberry Pi. This tutorial has shown you how to enable the service even if you do not have a monitor and keyboard connected to your Raspberry Pi. If you have the peripherals connected, then you can choose the method that suits you best.

Make sure you take a few basic steps to secure your device. If you need a reminder on the most common SSH commands, refer to our Linux SSH commands guide.

Источник

How to Enable and Use SSH on Raspberry Pi 4 (Raspberry Pi OS/Raspbian)

In this tutorial you’ll learn how to enable ssh on Raspberry Pi 4, with the Raspberry Pi OS (previously Raspbian).

On Raspberry Pi OS, ssh is disabled by default, so you’ll have to find a way to enable ssh + find the IP address + connect to it.

I will separate the tutorial into 2 parts:

  • Enable ssh if you’re using your Pi with a monitor and keyboard.
  • Enable ssh if you’re using your Pi headless.

I’ll also give you some extra configuration steps so everything will run smoothly later on when you work on your Pi via ssh.

Using ssh (“Secure Shell”) is one of the best way to work with your Raspberry Pi board(s). It will allow you to work on your Pi remotely, and you can also easily work on multiple boards at the same time from only one computer.

Table of Contents

First – Flash Raspberry Pi OS (Raspbian) into your micro SD card

Before we start, make sure you’ve flashed the Raspberry Pi OS into a micro SD card (class 10, at least 8GB). If you already did that, go to the next step.

You are learning how to use Raspberry Pi to build your own projects?

Check out Raspberry Pi For Beginners and learn step by step.

You can also the Raspberry Pi Imager directly, which will download and flash the image all at once.

Alright, now let’s enable ssh on the Pi.

New feature: Enable SSH directly when you flash the SD card

This is quite convenient: you can directly enable SSH before writing the operating system into the SD card. Note that this only works if you’re starting from scratch, not if you’ve already flashed the OS. In the latter case, skip this part of the tutorial. If you’re starting from scratch, let’s start!

So, before writing the operating system on the SD card, click on the “settings” icon.

Click on “Enable SSH”, and set a username + password. You will need to remember this username/password for when you will connect to the Raspberry Pi via SSH.

Also, scroll down a bit and enable Wi-Fi. Make the Raspberry Pi board connect to the same Wi-Fi network as your laptop/computer.

Then, save and click on “write”.

Now that you’ve done this step, you can go directly to the “Find the Raspberry Pi’s IP address” part below (either with a monitor/keyboard, or without). You have enable SSH but you still need to find the IP address to be able to connect to the Raspberry Pi.

Enable ssh on Raspberry Pi 4 with a monitor and keyboard

So, you already have a working operating system on the SD card and don’t want to flash it again?

Let’s first see how you can enable ssh on your Raspberry Pi 4, when using an external monitor + keyboard + mouse.

Initialization

If this is the first time you boot your Pi with your new image, then follow the steps of the “Welcome” screen. You will:

  • Select a country, language, keyboard layout, timezone.
  • Connect to a Wi-Fi network.
  • Change the default password (user: “pi”, password: “raspberry”).
  • Update packages to their newest version.

The important thing you need for the following is that the Raspberry Pi 4 (ssh server) is connected to the same Wi-Fi network as your computer (ssh client).

Enable ssh from the Raspberry Pi 4

First, open a new terminal.

Execute sudo raspi-config .

You will see this menu (or something very similar).

Select “Interfacing Options” and press ENTER.

Then, select “SSH” and press ENTER.

Select “Yes”, press ENTER, and you’ll get a message “The SSH server is enabled”.

Then, you’ll see the raspi-config menu again, press ESCAPE to quit.

Find the Raspberry Pi’s IP address

To connect to the Pi from your computer, you’ll need to know the IP address of the Pi.

Well, as you’re already working from the Pi, that’s really easy.

Simply open a terminal and run hostname -I . This will give you the IP address of the Pi inside the Wi-Fi network it’s connected to.

Here in my case: 192.168.43.56. Of course you will certainly have a different value.

Connect to the Pi via ssh

If you’re using Linux, Mac OS, or Windows 10 (with at least the October 2018 update), you can simply use a ssh client from a terminal. If you’re using a previous version of Windows, you can download and use the Putty software.

So, open a new terminal on your computer. In Windows 10, search for “cmd” or “terminal” in the search bar.

Then, to be able to create a successful connection, you need 3 things:

  • the IP address of the Pi: well that’s just what we got from the last step.
  • username: this is the username you have on your Pi. The default one with Raspbian is “pi”. (on your Pi, execute whoami to check the username)
  • password: by default this is “raspberry”, but you should already have changed it in a previous step.

To create a ssh client and thus connect to the Raspberry Pi 4, execute: ssh username@ip_address , and then provide the password.

Great, you’re now connected to the Pi with ssh! Working in this terminal (session) is the same as if you work directly on the Pi (with a monitor + keyboard).

Enable ssh on Raspberry Pi 4 without any monitor

Here comes a greater challenge: what if you don’t have an extra monitor + keyboard to first enable ssh on your Raspberry Pi 4? Or… What if you’re just too lazy to setup all the hardware? (I know I am)

Well, you can enable ssh on your Pi without any monitor, and it’s not that hard. Let’s get started.

(note: if you’re willing to flash the SD card again – and loose all data – you can go back in the tutorial and learn how to enable SSH + Wi-Fi directly on the SD card. If not, read on.)

Make the Pi automatically connect to Wi-Fi

You may directly plug an Ethernet cable between your computer and your Pi, so they’re both already in the same network, but let’s say that we’re not going to use an Ethernet cable here.

So, before we can even think of ssh, we first need to make sure the Pi can connect to the Wi-Fi network.

Put your micro SD card back into your computer, and navigate into its root folder (named “boot”).

Here create a file named “wpa_supplicant.conf” (remove any other extension like “.txt”).

Open this file with any text editor (on Windows -> right click + “Open with”), and write the following:

Replace WIFI_NETWORK_NAME and WIFI_PASSWORD with the actual name and password of your Wi-Fi network.

Save and quit the file.

Great, now the Pi should automatically connect to the Wi-Fi network on boot. But, before you remove the SD card, let’s configure ssh.

Enable ssh directly on the SD card

Here it’s really simple. Still in the root folder of your SD card (“boot”) create a new file named “ssh”, with no extension.

That’s it! This will enable ssh when you boot the Pi.

Now, remove the micro SD card from your computer, make sure the Pi is powered off, put the SD card into the Pi, and power it on.

Find the Raspberry Pi’s IP address

As you don’t have a direct access to your Pi, you’ll need to find its IP address from your computer.

On Windows, you can download and install Advanced IP Scanner. Open the software and press “Scan”.

Here you can see, we have a machine named “raspberrypi” on the network, and we also have its IP address!

>> Watch this for a complete tutorial on how to use Advanced IP Scanner:

Alternative: if you want a software with a graphical interface that runs on both Windows, Linux, and MacOS, use Angry IP Scanner.

If you’re on Linux, you can use the nmap tool ( sudo apt install nmap ).

Let’s say the IP address of your computer is 192.168.43.138, then you can execute:

And you also find the IP address of the Pi.

>> Watch this for a video explanation on how to use nmap:

Connect to the Raspberry Pi 4 via ssh

Well, now it’s the same as before (when we setup ssh with a monitor). From your computer, open a terminal and execute ssh username@ip_address .

Here the username is “pi”, and the password is “raspberry” since we haven’t changed it yet.

If you see this line -bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) , there is a problem with the locale setup, and you can fix it by executing those commands:

Also, as you can see in the logs, now might be a good time to change the password with passwd .

And also update/upgrade your packages:

Your Raspberry Pi 4 is now configured and you can continue to work on it via ssh!

Conclusion

In this tutorial you’ve seen how to enable ssh on Raspberry Pi 4, using the Raspberry Pi OS (previously Raspbian).

Sometimes you will want to work with a monitor, sometimes not. And that gives you 2 ways of setting things up. At the end, once your Pi is connected to the Wi-Fi network, and ssh is enabled, well it is the same whether you use a monitor or not.

From your computer, you’ll simply open a terminal (from Windows 10/Linux/MacOS), and you’ll ssh into the Pi. You can create multiple clients to open multiple sessions on the Pi.

This tutorial was for Raspberry Pi OS (Raspbian), but maybe you’ll also want to try to install Ubuntu on your Pi: here is how to setup ssh when using Ubuntu.

Did you find this tutorial useful?

Do you want to learn how to build awesome projects with Raspberry Pi?

If yes, this course is for you:

Did you find this tutorial useful?

Do you want to become better at programming robots, with Arduino, Raspberry Pi, or ROS2?

If yes, subscribe to receive exclusive content and special offers!

Источник

Поделиться с друзьями
КомпСовет
Adblock
detector