Raspberry Pi Headless Setup (and other things) · GitHub
※ Raspberry Pi Headless Setup ※
Installation of Raspbian OS on SD card
-
Download Raspbian image: https://www.raspberrypi.org/downloads/raspbian/.
-
Unzip it (optional).
-
Format SD card with SD Memory Card Formatter application (https://www.sdcard.org/downloads/formatter/).
-
Open Etcher application (https://www.balena.io/etcher/)
-
Select from hard drive the Raspbian .img or .zip file.
-
Select the SD card.
-
Click [Flash].
Enable SSH on a headless Raspberry Pi
-
Place a file named
ssh
, without any extension, onto the boot partition of the SD card:$ cd /Volumes/boot $ touch ssh
-
Eject card.
Set up wireless networking (for devices with WiFi)
-
Create a file named
wpa_supplicant.conf
in the boot partition:$ cd /Volumes/boot $ nano
-
Write the configuration for the wireless network(s):
(file)
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid=“ssid-name1” scan_ssid=0 psk=encrypted-password priority = 2 } network={ ssid=“ssid-name2” scan_ssid=0 psk=encrypted-password priority = 1 }
(end of file)
-
Save and exit:
[Ctrl + O]
[Ctrl + X] -
Eject card.
Insert card on Raspberry Pi and power it on
Change hostname
-
Change “raspberrypi” to the new hostname, save and exit:
$ sudo nano /etc/hostname
-
Find line starting with 127. 0.0.1 and change “raspberrypi” to the new hostname, save and exit:
$ sudo nano /etc/hosts
-
Reboot
$ sudo reboot
Change login password
-
Change password:
$ passwd
Set up SSH key pairs
Some info: https://medium.com/risan/upgrade-your-ssh-key-to-ed25519-c6e8d60d3c54
SSH supports several public key algorithms for authentication keys.
The algorithm is selected using the -t
option and key size using the -b
option.
-
dsa — bad!
-
rsa — ok
Key sizes: 768 (min), 4096 (recommended), 16384 (max) -
ecdsa — good
Key sizes: 256, 384, 521 -
ed25519 — best
Key size: 256 (fixed)
To check all available SSH keys on the computer run:
for key in ~/. ssh/id_*; do ssh-keygen -l -f "${key}"; done | uniq
METHOD 1
-
On local machine
Use existing key in~/.ssh
or generate a new one withssh-keygen
:$ cd ~/.ssh $ ssh-keygen -t ed25519
-
On local machine
Install the SSH key on the Raspberry Pi as an authorized key withssh-copy-id
:$ ssh-copy-id -i ~/.ssh/<key> <user>@<host>
METHOD 2
-
On local machine
Use existing key in~/.ssh
or generate a new one withssh-keygen
:$ cd ~/.ssh $ ssh-keygen -t ed25519
-
On remote machine
Create the.ssh
directory and theauthorized_keys
file with the correct permissions:$ mkdir .ssh $ touch ~/.ssh/authorized_keys $ chmod 700 ~/.ssh $ chmod 600 ~/. ssh/authorized_keys
-
On local machine
Copy SSH public key to Raspberry Pi:$ scp ~/.ssh/id_ed25519.pub pi@rpi:~/.ssh/
-
On remote machine
Add SSH public key toauthorized_keys
file:$ cd ~/.ssh $ cat id_ed25519.pub >> authorized_keys $ rm id_ed25519.pub
– Setup complete –
※ Other Things ※
Customised command prompt
-
Replace default prompt in
~/.bashrc
file with:# Custom prompt PS1='${debian_chroot:+($debian_chroot)}\[\033[01m\]\u@\h\[\033[01m\]:\[\033[01m\]\w \[\033[00;35m\]❯\[\033[00m\] '
Incremental history and completion
-
Add the following lines to file
~/.inputrc
:# Incremental history searching "\e[A": history-search-backward "\e[B": history-search-forward "\e[C": forward-char "\e[D": backward-char # TAB completion set completion-ignore-case on set show-all-if-ambiguous on set show-all-if-unmodified on
Create custom SSH/login message
-
Edit static text:
$ sudo nano /etc/motd
-
Edit dynamic content:
$ cd /etc/update-motd. d
-
Create/edit file:
$ sudo nano /etc/update-motd.d/10-uname
(file)
#!/bin/sh uname -snrvm echo "\033[00;32m●\033[00m Connected to `iwgetid`\033[00m"
(end of file)
Install tmux
-
Download and install:
$ sudo apt-get install tmux
User management
-
To create user:
$ sudo adduser user
-
To add new user to sudoers:
Some info: https://www.garron.me/en/linux/visudo-command-sudoers-file-sudo-default-editor.html$ sudo visudo
Edit the file as below:
# User privilege specification root ALL=(ALL:ALL) ALL user ALL = NOPASSWD: ALL
Save and exit.
-
To delete user:
$ sudo userdel -r user
Setup WiFi
-
Encrypt WiFi password:
$ wpa_passphrase {ssid} {password}
-
Edit configuration:
$ sudo nano /etc/wpa_supplicant/wpa_supplicant. conf
(file)
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid=“ssid-name1” scan_ssid=0 psk=encrypted-password priority = 2 } network={ ssid=“ssid-name2” scan_ssid=0 psk=encrypted-password priority = 1 }
(end of file)
Managing WiFi
-
Check network being used:
$ iwgetid
-
List of available networks:
$ wpa_cli > scan > scan_results
-
Info about wireless network interface (wlan0/1):
$ iwconfig wlan0 $ sudo iwlist wlan0 scan | egrep "Cell|ESSID|Signal|Rates"
-
Disable power management for WiFi:
$ sudo iwconfig wlan0 power off
Add this to the
/etc/rc.local
file so it runs when RPI restarts. -
Disable WiFi
$ sudo ifconfig wlan0 down
To keep WiFi off across boots, add this line to
/boot/config. txt
:dtoverlay=disable-wifi
Attach USB storage
-
Plug USB disk in.
-
List available block storage devices with UUIDs and free disk space:
$ lsblk $ lsblk -f $ df -h
External drives will have the name sdx, where x=a,b,c,…
Some info: https://www.linuxnix.com/lsblk-command-explained-with-examples/ -
Create partitions:
$ sudo fdisk /dev/sda Command (m for help): o (wipe existing partitions) Command (m for help): n (add new partition) Select (default p): [ENTER] Partition number (1-4, default 1): [ENTER] First sector (2048-613355519, default 2048): [ENTER] Last sector, +sectors or +size{K,M,G,T,P} (2048-613355519, default 613355519): [ENTER] Command (m for help): w (write changes)
-
Check the new partition was created:
$ sudo fdisk -l $ sudo fdisk -l /dev/sda
-
Format partition and attach a label:
$ sudo mkfs. ext4 -L U1 /dev/sda1 /dev/sda1 contains a ext4 file system - Proceed anyway? (y,n): y
-
Create mount point:
$ sudo mkdir /mnt/u1
-
Mount:
$ sudo mount /dev/sda1 /mnt/u1
-or-
$ sudo mount -L U1 /mnt/u1
-
Test mount point:
$ ls /mnt/u1/
-
Configuration for mounting drive at system boot:
$ sudo nano /etc/fstab
Add line after last partition of the list:
LABEL=U1 /mnt/u1 ext4 defaults,auto,noatime,rw,users 0 0
(UUID can be used instead of LABEL, run
blkid
to list the partitions and their UUIDs)Save and exit:
[Ctrl+O]
[Ctrl+X] -
Reboot:
$ sudo reboot
-
Change and verify permissions:
$ sudo chown pi:pi /mnt/u1 $ sudo chmod 755 /mnt/u1 $ ls -l /mnt/ drwxr-xr-x 3 pi pi 4096 Nov 4 21:27 u1
-
Check filesystem for errors:
$ sudo umount /mnt/u1 $ sudo fsck -Mn /dev/sda1
Install & configure remote.
it
Some info: https://docs.remote.it/platforms/quick-start-on-raspberry-pi/install-remote.it
-
Install the remote.it
connectd
package:$ sudo apt install connectd
-
Run the interactive installer:
$ sudo connectd_installer
Install & configure RealVNC
Some info: https://help.realvnc.com/hc/en-us/articles/360002249917-VNC-Connect-and-Raspberry-Pi
-
Install RealVNC:
(pre-installed on Raspbian)$ sudo apt-get update $ sudo apt-get install realvnc-vnc-server
-
Start virtual desktop:
$ vncserver :<display-number> -geometry 1600x1200 -randr 1600x1200,1440x900,1024x768
-
Resize with:
$ xrandr -s 1600x1200 $ xrandr -s 1440x900 $ xrandr -s 1024x768
-
Convenient to put all of these options in
~/. vnc/config
file:-randr 800x600,1024x768,1280x800,1280x960,1280x1024,1680x1050,1920x1080,3360x1050,1024x700,1200x740,1600x1000,3200x1000
-
Stop virtual desktop:
$ vncserver -kill :<display-number>
Useful commands
-
To start VNC Server now:
$ sudo systemctl start vncserver-x11-serviced.service
-
To start VNC Server at next boot, and every subsequent boot:
$ sudo systemctl enable vncserver-x11-serviced.service
-
To stop VNC Server:
$ sudo systemctl stop vncserver-x11-serviced.service
-
To prevent VNC Server starting at boot:
$ sudo systemctl disable vncserver-x11-serviced.service
Boot actions
-
Execute commands:
$ sudo nano /etc/rc.local
Add the commands or scripts before the
exit 0
so it runs when RPI restarts.
Some info : https://www.raspberrypi.org/documentation/linux/usage/rc-local.md -
Change configuration parameters:
$ sudo nano /boot/config.txt
Add the changes as needed. Example:
dtoverlay=disable-wifi
Some info: https://www.raspberrypi.org/documentation/configuration/config-txt/See
/boot/overlays/README
for more info:
https://github.com/raspberrypi/firmware/tree/master/boot/overlays -
Run scripts:
$ crontab -e
Use
@reboot
at the begining of the line and&
at the end.
Example:@reboot python /home/pi/example.sh &
[Ctrl + O]
[Enter]
[Ctrl + X]Crontab man page: https://manpages.debian.org/buster/cron/crontab.5.en.html
Crontab tool: https://crontab.guru
Raspberry Pi 3/0W SSH over WiFi Fix
-
Edit the two configuration files:
/etc/ssh/ssh_config
/etc/ssh/sshd_config
-
Add the following line to the bottom of each configuration file:
# RaspberryPi Zero W Onboard WiFi Fix IPQoS 0x00 #IPQoS cs0 cs0
-
Restart
ssh
andsshd
:$ sudo systemctl restart ssh $ sudo systemctl restart sshd
https://www. raspberrypi.org/forums/viewtopic.php?f=28&t=138631&start=125
guysoft/OctoPi#294
IPQoS 0x00
https://forum.core-electronics.com.au/t/pi-zero-w-problem/944/4
#RaspberryPi 3 Onboard WiFi Fix
IPQoS cs0 cs0
https://community.openenergymonitor.org/t/ssh-issues-specific-to-pi3-onboard-wifi/2730
How to enable SSH in Raspberry Pi? (Headless)
What is SSH?
The SSH protocol (also referred to as Secure Shell) is a method for secure remote login from one computer to another. It provides several alternative options for strong authentication, and it protects the communications security and integrity with strong encryption.
In our case we use our Desktop/Android device to logic to our Raspberry Pi remotely.
What will be covered?
- STEP 1: Download and setup Raspbian OS
- STEP 2: Enable SSH
- STEP 3: Connect to a network(wifi or LAN)
- STEP 4: Find the IP address of your Pi
- Final STEP: SSH login
STEP 1: Download and setup Raspbian OS
Note:Skip this step if you have already setup the Raspbian in pi beforehand.
- To download the latest Raspbian OS first download Any One from here .
- Next, download and install BalenaEtcher from here.
- Insert SD card to your computer and open BalenaEtcher .
- Select the raspbian image you downloaded earlier.
- Select your SD card
- Finally click on Flash!
It will take some time(Have patience or a cup of tea :P) to complete the Flashing process.
Finally This part is done!!
STEP 2 : Enable SSH
- First, remove and reinsert SD card to the computer once it is flashed.
In Linux :
Simply open a terminal and create a file named “ssh” in the boot directory of the SD cardby using the below command
nano ssh
In Windows:
- First, open the “boot” Directory from “This PC“.
- Next,Create a new “text document” like this in the “boot” directory named ssh
- Now we need to remove the extension of this file i.e from “ssh.txt” to “ssh”
- For this go to the view tab and check the checkbox “File name extensions” under Show/hide.
- Now,your file will look like this(Extension is displayed along with file name)
- Next just rename the file and remove the extension.
- Once done the file type will change to “File” from “Text Document”
That is it. With the next boot, SSH will be enabled.
STEP 3: Connect to a network(wifi or LAN)
First Method -Using LAN or Ethernet: In this method just connect your Pi to your router using an ethernet cable and power on the Pi. This will automatically connect your Pi to your local network.
Second Method Using Wifi: For this, we need to add another file inside the “boot” directory with the file name “wpa_supplicant.conf“
- Now open this file “wpa_supplicant.conf” with any text editor(i used notepad) and type the following and save it:
country=IN update_config=1 ctrl_interface=/var/run/wpa_supplicant network={ scan_ssid=1 ssid="Replace with your wifi name/SSID" psk="Replace with the wifi password " }
Country Code should be set using the ISO/IEC alpha2 code for the country.
This part is done !!
STEP 4: Find IP address of your Pi
To connect to your Raspberry Pi remotely, you need two things (we’ll help you find them):
- Its IP address on the local network
- An SSH client (SSH is a communication protocol between machines)
First power on the pi and wait for few seconds for the pi to boot up.
Next, we need to find the IP address of pi on your network. For this we can use any method
I use an app called Network Scanner to find the ip address.(playstore link)
Final Step :SSH login
Now open Cmd in windows or Terminal in linux and type:
ssh [email protected]
Here my IP address was “192.168.31.6”.Replace with your IP address.
- Type yes and press Enter.
- Now enter the password as “raspberry”.[This is the default password.]
Note: when you type the password it is not visible on the screen .This is normal no need to worry.just type it and press enter.
- Now you have access to the command line of your Raspberry Pi remotely from another computer or device on the same network using SSH.
That’s it !! You have successfully connected via SSH into Pi.
How to Set Up a Raspberry Pi Headless
The Raspberry Pi is a computer that can do so much in such a small and discrete form-factor.
I’m going to show you how you can set up your Raspberry Pi to automatically enable SSH and connect to Wi-Fi without the need to configure this directly from the device, allowing you to use the Raspberry Pi without a keyboard or monitor connected.
Video Tutorial
Click here to display content from YouTube.
Learn more in YouTube’s privacy policy.
Always display content from YouTube
Getting Started
To get started, you’ll either need a new or existing Raspbian installation. I’ll be working with a new installation of Raspbian Lite that has been flashed and written to the card using Etcher.
To start off with, you’ll want to have your SD card plugged into your computer so we can save the necessary files to it.
Enabling SSH
Enabling SSH is straightforward. You’ll want to create a file named ssh
within the boot directory of the SD card. It is important to ensure that this file does not have a file extension, or it will not work.
The easiest way to create this file will be to open Windows Explorer and browse to the boot directory. Now you’ll want to enable file name extensions within Windows Explorer, go to View
at the top and check the File name extensions
checkbox, this will allow us to check that the file we create does not have an extension.
Creating a file named “ssh” will enable SSH when the Pi boots up
To create the file, right-click within the directory and select New > Text document
. Select the all the “New Text Document.txt” placeholder text and replace it with “ssh”, ensuring that there is no file extension.
Adding Network Information
Now that SSH is set to be automatically enabled when the Raspberry Pi boots up, we’ll want to give it some network information so it can connect to the network over Wi-Fi. To do this, we’ll create another file in the boot directory.
Create a new file called wpa_supplicant.conf
, this is where we will enter the network information so it can be imported by the Raspberry Pi when the system boots.
Within this file you’ll want to insert the following code:
If you don’t want to type all of this out, visit the written article linked in the description so you can copy and paste the code over.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=<Insert country code here> network={ ssid="<Network Name>" psk="<Network Password>" }
You’ll also need to insert the ISO code of your country so that 5G networking will function correctly. You can find your country code on this handy list from Wikipedia, in my case I will need to add GB.
The configuration file will be imported by the operating system when it next boots
This configuration file should work for most networks, but if you have a different or more complex setup, you may need to add extra parameters to your configuration file which can be found on the Raspberry Pi documentation.
Once you’ve entered all the information you need, make sure to save and close the file.
Preparing the Pi
At this point all the configuration is done. You can eject the SD card from your computer and insert it back into the Pi and power it up. Give the Pi a minute or so to do its initial boot as it will need to implement the changes we’ve configured.
You can also now hide file extensions in Windows Explorer if you wish to do so.
Connecting to your Pi
Now we can connect to the Raspberry Pi over SSH, to do this I shall be using PuTTY which is an SSH client available for Windows. You’ll also need iTunes installed for this next part, an odd requirement I know, or Bonjour Print Services — this will allow our SSH client to discover the Raspberry Pi on the network using the hostname.
As we don’t yet know the IP address of the Raspberry Pi, we shall be connecting to it using its default hostname of raspberrypi. local
. If you wish to find out the IP address the best place to look will likely be your router’s administrator interface or the Fing app.
In PuTTY, enter raspberrypi.local
into the host box. By default, the port should be set to 22 and the connection type to SSH, click Open
to connect and accept the Security Alert if it pops up.
PuTTY is used to SSH into the Raspberry Pi
Once we’ve connected to the Raspberry Pi, we can log in using the default credentials of pi
and raspberry
and begin to use it however we want.
Wrapping Up
That’s how you can configure and use your Raspberry Pi headless, with only the power cable needing to be connected to it. I think it’s very cool how the Pi can be configured to do this and there is something novel about only needing to have a single power cable connected.
Raspberry Pi Headless Setup — Raspberry Valley
Time to prepare your Raspberry Pi for any project. The ‘headless’ in the title means we will be strictly using the terminal to setup everything and prepare the Pi to run both headless and in desktop mode.
You have a Rasberry Pi, you have downloaded Raspbian images (standard, light) and you now want to figure out how to get it running. You also don’t want to pull out your spare keyboard and screen and want to configure and run everything from your PC (remotely — all you need is a network connection). It turns out you can — and this guide tells you how.
Preparation
- Hardware check-list. Get the below ready for use.
- Raspberry Pi (any model)
- Network cable connected to Raspberry Pi and your local network
- Blank SD card: size recommendations differ based on the Raspbian version you choose, but 4GB recommended
- USB power adapter
- Setup the SD card with a chosen distro. Please check our dedicated guide Setup SD Card for details (choice of system, choice of tooling, a step-by-step setup guide)
- Insert the freshly created SD card into Raspberry Pi, switch on and wait a bit
- Locate your new IP address. You will need to note it down for first time connecting to your Raspberry Pi. There are zillions of tools out there to choose from. I suggest to use a simple and portable IP scanner — Softperfect Network Scanner — download here. Choose a portable version or install version as you wish
- TIP: run the tool 2 times: first instance — scan your network before plugging in the Raspberry Pi, in the second instance scan again after plugging in the Raspberry Pi: you can compare side by side what is the new IP added. Saves tons of time.
IMPORTANT: As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually in raspi-config in the terminal. For headless setups, SSH can be enabled by placing a file named ‘ssh’, without any extension, onto the boot partition of the SD card. Please do so now, otherwise your SSH connection below will not work!
SSH — Initial Configuration
Now you have your Rasberry Pi running and you know it’s IP address. Time to connect first time and setup some basics.
- First, SSH to your Raspberry Pi. I use MobaXTerm Personal which fulfills all my needs (and then some) but any SSH client will do. You can download it here. Note we have a dedicated recipe for SSH tools and connecting to devices found here: Remote Access to Raspberry Pi.
- TIP: the default username / password (as of this writing) is pi / raspberry. We’ll do something about that a few steps down
- MobaXTerm has a limit to number of connections in the free version. If you need to exceed it, just run the portable version in multiple instances — unlimited connections is what you get. A good idea is to have a dedicated version for your Pis.
- Run the Raspberry Pi configuration tool bundled with your distro — raspi-config — to set basic settings. We will revisit later for more sophisticated stuff.
sudo raspi-config
sudo apt update sudo apt full-upgrade sudo rpi-update
SSH — Finalizing Configuration
This section describes remaining configurations which might come in handy. Even now however, your Raspberry Pi is ready to run anything. Some of the sections are purely optional. So for each activity in this section, figure out whether it makes sense for your project or note
- Go ahead and finish configuring the system using the raspi-config utility. At this point in time it is worth mentioning that it is a good idea to learn the configuration tool. There are settings which you might want for a specific purpose of your device and are not mentioned here. Such as enabling the camera. Go ahead and add them to this list.
sudo raspi-config
-
Choose and configure the following sections in raspi-config
- Set the hostname in Advanced Options — Hostname: Name your Raspberry Pi to allow easy access to the device from other computers and to setup features like file-sharing in heterogenous networks
- Set locales and timezone in internationalization options, together with keyboard layout*. You can of course make life simple and set the timezone only, other things follow. And once the device boots and is connected to the internet, it should also pull the correct time
- Set the Advanced Options — Memory Split based on what you want to do with your device. For running completely headless, 16 Megs of graphics memory should suffice. Otherwise the current setting is probably the best
- Update the raspi-config tool in Advanced Options — Update
-
You might be asked at this point in time to reboot, do it now, whether asked or not
At this point in time it is safe and possible to access your Raspberry Pi not only via SSH. You can also browse your Raspberry Pi via SFTP (if you have not disabled the FTP server). We have a separate section describing this feature. To install the components, it is enough to run
- Time to install Samba. We have a full guide to setup all Samba related things in. This will, as a side-effect, enable the hostname to be visible.
sudo apt install samba samba-common-bin
and if you remember your configuration settings, edit the configuration file. As mentioned we have a whole samba recipe elsewhere.
sudo nano /etc/samba/smb.conf
If you need a quick copy-paste job when sharing the pi user folder, just take the configuration from below. But as mentioned, Samba is discussed in detail elsewhere
[pihome] comment= Pi Home path=/home/pi browseable=Yes writeable=Yes only guest=no create mask=0777 directory mask=0777 public=no
-
If you wish to have a static IP address for your device, do it now. I recommend to do this only if you have a very good reason. We have a separate recipe to do this: Static IP on Raspberry Pi.
-
Install additional software. This section is completely yours and is a placeholder to setup stuff you use on a daily basis. I usually consider setting up the following:
- Setup Midnight Commander: a bit of nostalgia for me probably, I do not use it so often — but my fingers still remember the shortcuts :):
sudo apt install mc
- Setup XRDP:
sudo apt install xrdp
- Setup Midnight Commander: a bit of nostalgia for me probably, I do not use it so often — but my fingers still remember the shortcuts :):
I love XRDP and prefer it to VNC server anytime. Probably because I use Windows a lot. However for most of desktops (including Pixel which is latest of this writing) you need to either choose XRDP or VNC Server. One or the other really. The Raspberry Pi site on Pixel describes this very clearly: «Please note that if you already use xrdp to remotely access your Pi, this conflicts with the RealVNC server, so you shouldn’t install both at once. If you’re updating an existing image, don’t run the
sudo apt install realvnc-vnc-server
line in the instructions below. If you want to use xrdp on a clean image, first uninstall the RealVNC server withsudo apt purge realvnc-vnc-server
before installing xrdp. (If the above paragraph means nothing to you, then you probably aren’t using xrdp, so you don’t have to worry about any of it!)».
- Install Arduino if you intend to do some Arduino development:
sudo apt install arduino
Where to Next?
Here is a list of where to go from here (on setting up your Raspberry Pi basic image). It does not cover applications, hardware configurations etc. but purely optional steps on setting up your base image. Those topics are covered in more detail elsewhere.
- Whether you chose a standard version of Raspbian or a Lite version, there will be software installed you simple don’t need. Time to cleanup things and re-claim some space. We have a cleanup section available elsewhere: Raspberry Pi Image Cleanup
- If you wish to spice up your Raspberry Pi a bit, you can also add a Message of the Day …
- Now is maybe the time to backup your image and use it next time as a starting point
Yet more Next steps
Similarly to the above section, you can configure even more features. Here are some tips
- If you have more Raspberry Pi devices, you can use the image you just created to setup a server side or client side for booting from network (applicable to Raspberry Pi 3 upwards)
- You can transfer your image to a USB device: that is you boot from USB, but the SD card is still present on models older than Raspberry Pi 3. For 3 upwards you can setup booting from a USB device or USB HDD (without SD card present)
Tips
- If you have setup more users, you might find that some have a different shell. To update to bash for a specific username, do this:
chsh -s /bin/bash <username>
-
As of the November 2016 release, Raspbian has the SSH server disabled by default. You will have to enable it manually. For headless setup, SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card.
-
If you have started with a full Raspbian installation on the SD card, you might want to remove the desktop. After all this article is all about headless, right? This will give you roughly 1GB of extra space on your machine. To achieve this, type the following in your terminal session:
sudo apt-get remove gnome-shell sudo apt-get remove gnome-session sudo apt-get autoremove
- Raspi-Config Non-interactive Mode: If you setup your Pi manually, you can skip this comment. However when you do automate your setup (for example with Ansible — see a gentle introduction here ), then running raspi-config interactive mode is not a good option. It turns out that you can run raspi-config in Non-Interactive mode (from the command-line). These features are mostly undocumented, but we can confirm we use them all the time. See more in this article — Raspi-config’s mostly undocumented non-interactive mode, or simply search for nonint Raspberry Pi commands.
- Raspbian Downloads
- Official Image Downloads — Choose other official distros
- Softperfect Network Scanner
- MobaXTerm
- Etcher
- Win32DiskImager
Built with MkDocs using a theme provided by Read the Docs.
Install Ubuntu Server on Raspberry Pi in Headless Mode and SSH Into It
Ubuntu is an open-source operating system. It is based on Debian GNU/Linux operating system. Ubuntu is a great operating system for your IoT projects on the Raspberry Pi 4.
In the headless setup of Ubuntu on Raspberry Pi 4, you don’t need a keyboard, a mouse, and a monitor. You can directly access the Ubuntu operating system installed on your Raspberry Pi 4 remotely via SSH.
In this article, I am going to show you how to install Ubuntu Server 20.04 LTS on your Raspberry Pi 4 in headless mode and configure SSH access. So, let’s get started.
Things You Will Need:
To follow this article, you need the following things:
- A Raspberry Pi 4 single-board computer
- A USB Type-C power adapter for your Raspberry Pi 4
- A 16 GB or 32 GB microSD card
- A laptop or a computer for flashing the Ubuntu Server image on the microSD card and accessing your Raspberry Pi 4 via SSH
- Raspberry Pi Imager or Balena Etcher installed on your laptop or computer for flashing the Ubuntu Server image on the microSD card.
If you need any assistance on installing Raspberry Pi Imager on your Linux operating system, check my article How to Install and Use Raspberry Pi Imager.
If you need any assistance on installing Balena Etcher on your Linux operating system, check my article Install Etcher on Linux.
In this article, I will use Raspberry Pi Imager for flashing the Ubuntu Server operating system image on the microSD card. You can use Balena Etcher if you want.
Downloading Ubuntu Server 20.04 LTS Image for Raspberry Pi:
To install Ubuntu on Raspberry Pi 4, you need to download the Ubuntu Server 20.04 LTS image for Raspberry Pi.
The Ubuntu Server 20.04 LTS Raspberry Pi image is available on the official website of Ubuntu.
Visit the official website of Ubuntu from your favorite web browser.
Once the page loads, click on Download and click on Raspberry Pi 2, 3, or 4 from the Ubuntu for the IoT section as marked in the screenshot below.
Once the page loads, scroll down a little bit and click on either the Download 64-bit or Download 32-bit button from the Ubuntu 20.04.1 LTS section as marked in the screenshot below.
If you’re using the 2GB or 4GB version of Raspberry Pi 4, then download the 32-bit Ubuntu 20.04 LTS image.
If you’re using the 8GB version of Raspberry Pi 4, then download the 64-bit Ubuntu 20.04 LTS image. Otherwise, you won’t be able to use the full 8GB RAM of your Raspberry Pi 4. A 32-bit operating system can address only 4GB of RAM.
Your browser should start downloading the Ubuntu Server 20.04 LTS image for Raspberry Pi shortly.
Once your browser prompts you to save the Ubuntu Server 20.04 LTS image for Raspberry Pi, select the location where you want to save the image, and click on Save.
Your browser should start downloading the Ubuntu Server 20.04 LTS image for Raspberry Pi. It may take a while to complete depending on the speed of your internet connection.
Flashing Ubuntu Server 20.04 LTS Image to MicroSD Card:
Once the Ubuntu Server 20.04 LTS image is downloaded, you can use Raspberry Pi Imager to flash the Ubuntu Server 20.04 LTS image to the microSD card.
Insert the microSD card on your computer. Then, open the Raspberry Pi Imager and click on CHOOSE OS.
Scroll down a little bit and click on Use custom.
Select the Ubuntu Server 20.04 LTS image that you’ve just downloaded and clicked on Open.
The Ubuntu Server 20.04 LTS image should be selected. Click on the CHOOSE SD CARD button as marked in the screenshot below.
Click on the microSD card from the list that you want to flash the Ubuntu Server 20.04 LTS image.
To write the Ubuntu Server 20.04 LTS image on your selected microSD card, click on WRITE.
To confirm the operation, click on YES.
This will remove all the existing data from the microSD card and copy the Ubuntu Server 20.04 LTS image file to the microSD card.
Ubuntu Server 20.04 LTS image is being flashed on the microSD card. It may take a while to complete.
Once the Ubuntu Server 20.04 LTS image is flashed on the microSD card, click on CONTINUE and close Raspberry Pi Imager.
Configuring Wi-Fi Connectivity:
NOTE: If you want to use Wi-Fi for network connectivity on your Raspberry Pi 4, then this section is for you. If you want to use a wired connection, then you can skip this step.
For the headless configuration of Ubuntu Server 20.04 LTS, you must configure the network (Wi-Fi or wired).
To do that, eject and re-insert the microSD card on your computer. You should see a boot partition as you can see in the screenshot below.
You should find a network-config file in the boot partition.
Open the network-config file in a text editor. The file should have the following contents by default.
Remove the # character from the marked lines (to uncomment the code). Then, change the <WiFi-SSID> and <WiFi-PASSWORD> with the SSID and password of the Wi-Fi network you want to connect to.
Once you’re done, save the network-config file.
Powering on the Raspberry Pi 4:
Connect the microSD card and the USB Type-C power cable on the Raspberry Pi 4.
If you want to use a wired network, connect the RJ45 network cable to the Ethernet port of the Raspberry Pi 4 as well.
Once you’re done, power on the Raspberry Pi 4.
Finding the IP Address of your Raspberry Pi 4:
Login to your Router’s admin panel from a web browser and you should find the IP address of your Raspberry Pi 4 that is assigned to it via the DHCP server running on the Router of your home network.
As you can see, the IP address of my Raspberry Pi 4 is 192.168.0.104. It should be different in your case. So, make sure to replace it with yours from now on.
Accessing the Ubuntu Server 20.04 LTS Remotely via SSH:
To remotely access the Ubuntu Server 20.04 LTS operating system running on your Raspberry Pi 4 via SSH, run the following command:
$ ssh [email protected]
To accept the fingerprint, type in yes and press <Enter>.
The default password is ubuntu. Type in ubuntu and press <Enter>.
The first time you log into Ubuntu Server 20.04 LTS on your Raspberry Pi 4, you will be asked to change the default password ubuntu.
Type in ubuntu and press <Enter>.
Type in a new password and press <Enter>.
Retype the password and press <Enter>.
The password should be changed and the SSH session should be closed.
You can SSH into your Raspberry Pi 4 again with the following command:
$ ssh [email protected]
Type in the new password and press <Enter>.
You should be logged into the Ubuntu Server 20.04 LTS operating system installed on your Raspberry Pi 4.
As you can see, I am running Ubuntu 20.04.1 LTS on my Raspberry Pi 4.
$ lsb_release -a
Now, you can run any command you want on your Raspberry Pi 4 remotely via SSH.
Conclusion:
In this article, I have shown you how to install Ubuntu Server 20.04 LTS on your Raspberry Pi 4 in headless mode (without a monitor, a keyboard, and a mouse connected to your Raspberry Pi 4). I have also shown you how remotely manage your Raspberry Pi 4 via SSH.
Raspberry PI headless setup with the Raspberry PI Imager
Planning on running your Raspberry PI system as a server? In this article I’ll show you how you can setup your Raspberry PI as a headless system. So one without a monitor, keyboard and mouse. Thanks to the relatively new Raspberry PI Imager software it is quick and easy to perform such a Raspberry PI headless setup. Especially if you know how to access the hidden advanced options screen of the Raspberry PI Imager software.
Background
A headless system is one without a monitor, keyboard and mouse attached. Perfect in case you want to run your Raspberry PI system as a server. Usually, you would still need to attach at least a monitor and a keyboard to perform the initial installation, but in this article I’ll show you how you can perform such a headless setup of your Raspberry PI, without needing a monitor and keyboard.
In the past I already explained how to perform such a headless setup of your Raspberry PI. In that tutorial we used the dd
command for writing the operating system to the SD card. Afterwards, we still had to manually edit a few configuration files on the SD card to make the headless setup work. Thanks to the relatively new Raspberry PI Imager software, setting up your Raspberry PI as a headless system becomes much quicker and easier. Enough to warrant a new article to this topic in my opinion.
The Raspberry PI Imager was first released in early 2020. It’s an easy-to-use graphical user interface application that ships with a few extra perks:
- Through the user interface, you can select which operating system you want to install, and the Raspberry PI Imager will download it automatically for you.
- With the Raspberry PI Imager you can restore the EEPROM bootloader on your Raspberry PI and configure the boot order.
- It has a hidden advanced options screen (Ctrl+Shift+x) to preconfigure the Raspberry PI operating system. For example changing the default hostname, enabling SSH and configuring the WiFi network connection.
Specifically this last feature, the advanced options screen, makes setting up your Raspberry PI as a headless system a breeze. Read on and I’ll show you how it’s done, including the installation of the Raspberry PI Imager software on your Linux system
What do you need
As the article’s title implies, we’ll obviously need a Raspberry PI. It doesn’t matter which one. I decided on using my Raspberry PI Zero W for this article. In addition to the Raspberry PI itself, you’ll also need:
- Power supply for your Raspberry PI.
- Micro SD card on which we’ll install the Raspberry PI operating system.
- USB card reader for connecting the micro SD card to your PC, unless your PC comes with an integrated micro SD card reader.
Ideally your PC runs a Linux operating system, but for this article it’s not absolutely necessary. The Raspberry PI Imager software is cross-platform so you could also use Windows or macOS.
Install the Raspberry PI Imager software
At the time of this writing, the Raspberry PI website only offers a download for the Raspberry PI Imager software for Ubuntu. To circumvent this restriction, I packaged the Raspberry PI Imager software for other popular Linux distributions, including Debian, Fedora and openSUSE. The resulting packages are hosted in PragmaticLinux’s account on the openSUSE Open Build Services infrastructure:
The remainder of this article assumes you installed the Raspberry PI Imager software on your Linux system. Refer to the article about how to install the Raspberry PI Imager on Ubuntu, Debian, Fedora and openSUSE for detailed installation instructions.
Prepare the SD card with the Raspberry PI Imager
Now that you installed the Raspberry PI Imager software on your system, we continue with preparing the SD card for your Raspberry PI headless setup.
Select the operating system and storage
Make sure you inserted your SD card into your PC and start the Raspberry PI Imager software. First we select the operating system by clicking the CHOOSE OS button on the user interface. Since we plan on installing the Raspberry PI operating system as a headless setup, we do not need a desktop environment. For this reason, the Lite edition of the Raspberry PI operating system suffices. Next, click the CHOOSE STORAGE button on the user interface to select our SD card as storage:
Configure the advanced options
The trick to creating a headless setup for your Raspberry PI, lies in the advanced options of the Raspberry PI Imager software. The advanced options dialog is a bit hidden. To access it, press the CTRL+SHIFT+x combination on your keyboard.
For a headless setup of the Raspberry PI operating system, the most important option is to Enable SSH. This allows you to remotely access and administer your Raspberry PI. The default password for the pi user is normally raspberry. You can change it to something harder to crack right away:
When we connect to the Raspberry PI via SSH later on, we need to know its hostname. After enabling SSH, you should therefore also set its hostname. The default raspberrypi
hostname works fine:
If you plan on connecting your Raspberry PI to your local network via WiFi, then check the box for Configure wifi. Next, enter your WiFi network name in the SSID box and specify the password to gain access. Finally, select your country from the Wifi country drop-down selection box.
We create a headless setup for our Raspberry PI, without desktop environment. For this reason, it is pointless to run the configuration wizard upon first boot. We can disable this first-run wizard, by checking the box Skip first-run wizard:
Optionally, you can check the box for Set locale settings and configure the time zone and keyboard layout. Once done with configuring the advanced options, click the Save button on the dialog.
Write the Raspberry PI operating system image to the SD card
Once back on the main screen of the Raspberry PI Imager, click the Write button. This starts the process for writing your selected and configured Raspberry PI operating system to the SD card.
Upon successful completion of the write operation, the Raspberry PI Imager presents you with the following dialog:
Boot your Raspberry PI and connect via SSH
With the SD card prepared for running the Raspberry PI operating system as a headless setup, we can give it a try. Make sure that you disconnected the power supply from your Raspberry PI. Next, remove the SD card from your PC and insert it in the SD card slot on your Raspberry PI. Next, connect the power supply to your Raspberry PI. This boots the Raspberry PI operating system for the first time. Give it a few minutes or so for the boot process to complete.
Once booting completed, you can attempt to remotely connect to it via SSH. Open up your terminal and type the following command. Enter the password for the pi
user. It’s the one you specified on the advanced options dialog previously.
ssh [email protected]
This completes the basic Raspberry PI headless setup. However, a few more optional yet recommended steps follow in the sections below.
Update your Raspberry PI system
After completing the initial headless setup of your Raspberry PI, it’s a good idea to update the operating system packages. This applies the latest security fixes for the currently installed packages. While logged in via SSH, run these two commands:
sudo apt update
sudo apt upgrade
In the previous screenshot you can see that the upgrade operation installs a new kernel (raspberrypi-kernel
). In this case it is recommended to reboot the system, after the upgrade finishes:
sudo reboot
And while performing some system maintenance, you might as well remove packages that are no longer needed:
sudo apt autoremove
For additional background information on performing system maintenance with APT, refer to the article on how to update Ubuntu using APT in the terminal.
Further secure your Raspberry PI
After completing the headless setup of your Raspberry PI and updating the installed packages, you could take a few extra steps to improve its security. Everyone knows that the default user account of the Raspberry PI operating system has username pi
. Why not create a new user account and delete the pi
one? Here’s how:
- Delete the pi user from your Raspberry PI.
If you have more than one Raspberry PI on your network, then you need to make sure to assign a unique hostname to each Raspberry PI. You can already do this in the advanced options dialog of the Raspberry PI Imager software. In case you forget or want to change it later on, follow the instructions in this tutorial:
- How to change the hostname of your Raspberry PI.
Logging in with a username and password combination is not the most secure. For an unwanted third party, it’s just a matter of patience before they could eventually find the right username and password combination. It’s more secure to login with an SSH key pair and then disable password logins altogether:
- Configure SSH for login without a password.
Wrap up
After working your way through this article, you learned how to setup your Raspberry PI as a headless system. Perfect if you plan on running your Raspberry PI as a server. Thanks to some of the advanced options of the Raspberry PI Imager software, this headless setup is quick and easy. In summary, this article covered these topics:
- Installing the Raspberry PI Imager software on your Linux system.
- Using the Raspberry PI Imager software to download, configure and write the Raspberry PI Lite operating system to the micro SD card.
- Booting your Raspberry PI headless system for the first time.
- Applying the latest security patches to the currently installed packages.
- Further securing your Raspberry PI, by deleting the
pi
user account and configuring logins with the help of an SSH key pair.
Where to go from here? Well, you probably already had a purpose in mind for your Raspberry PI headless server. If not, then here is a suggestion: Configure your Raspberry PI headless system as a web server. The following two articles will help you get started:
- Install a LAMP stack (Linux/Apache/MySQL/PHP).
- Install phpMyAdmin for managing MySQL databases.
Configuring the Raspberry Pi for headless use with SSH
The Raspberry Pi is — as we’ve seen in several previous articles — an extremely flexible piece of hardware. Once you’ve installed an operating system, mastered the small footprint, and found a fit for it, you can install the media center software and maybe even start programming the software (after all, that’s what it was designed for). !).
However, you may find that connecting your Raspberry Pi to a large-screen plasma TV—the only device in your house with an HDMI connection—is a bit tedious while your family is watching their favorite show. Also, you may have more than enough HDMI displays but not enough keyboards.
Benefits of SSH
Fortunately, the Raspberry Pi can accept SSH commands when connected to a local network (via Ethernet or Wi-Fi), making it easy to set up.
The benefits of SSH don’t limit daily viewing The Simpsons or the latest celebrity news — using a Raspberry Pi without a dedicated display (aka «headless») can allow you to leave the device in a certain configuration without worrying about someone else hinders.
Using the Pi as a NAS interface? No problem! If your Raspberry Pi spends its life as a low volume web server or internet radio, then it doesn’t need a dedicated display.
That’s where SSH comes in!
Configuring your Raspberry Pi for SSH
To prepare your Raspberry Pi for remote SSH connections, you must first install the Debian Raspbian distribution as described earlier. SSH is enabled by default, but if you have it disabled, you must enter the configuration screen to re-enable it.
After connecting the minicomputer to the network and connecting the keyboard and Ethernet cable, boot up and log into the device.
Once you’ve done that, type sudo raspi-config, to open the configuration screen, and use the arrow keys and Enter to select the Enable or Disable SSH option. On the next screen select «Enable», press «Enter» and again on the last screen «Enter» to select «OK».
Now that SSH is enabled, you can remotely connect to your Raspberry Pi using an SSH client.
(Note that if SSH is not listed as a menu option, you are probably using an old build of the Raspbian distribution and should upgrade as soon as possible!) -address. There are several ways to do this.
First, from the command prompt, type ifconfig to display the network connection details, including the IP address. In addition, you can check the router for connected devices and thus determine the IP address.
With this information, you are ready to connect to SSH.
If you’re on Windows, the best SSH tool is probably PuTTY, available at http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html . Once downloaded (choose putty.exe for this task), double-click the executable — it will run without installation.
On the Session screen, add the IP address in the Host Name field and press Open . PuTTY will give you a security notice — click Yes, to continue and log into your Raspberry Pi.
In a few minutes you will see the Raspberry Pi text interface!
You can now disconnect your keyboard, mouse, and HDMI cable from your Raspberry Pi and execute commands remotely.
Issuing Remote Pi Commands
Various commands can be sent remotely to the Raspberry Pi via SSH — pretty much anything that doesn’t disable or interrupt SSH or your network connection!
ps ax
This will display a list of running processes.
$ ssh –V
Displays the current version of SSH
Files can be copied to and from the Raspberry Pi using SSH:
localhost $ scp login: /home/username/remotehostfile.txt remotehostfile.txt
localhost scp localhostfile.txt username: /home/username/localhostfile.txt
Once you’re done, don’t forget to safely shut down the Pi with the command:
sudo shutdown -h now
(Changing -h to -r will reboot the device). This must be done before removing the power cable — if this is not done, it may damage the SD card, which will mean reinstalling the Raspian OS.
Updates, application installations and command line usage — Remote!
There are certain things that SSH is not good for. For example, it won’t let you access the Raspberry Pi GUI, but it will give you the means to run updates, install apps, and use various firmware and tools from another computer.
With a simple SSH setup using the remote control and the above commands (and many more), you can quickly and efficiently send instructions to a device using PuTTY on Windows or using the built-in command line tools on Mac OS X and other Linux distributions.
In general, if you have a Raspberry Pi, you should know how convenient and useful SSH is. If you plan on using SSH regularly, you might want to learn how to hack this boot partition. hack is a hack to quickly enable SSH when you need it.
how to activate, install and connect
Recently, a separate class of devices has become widespread, designed to control equipment, use as small workstations or create simple servers. We are talking about computers on a single board, such as the Raspberry Pi. Despite their size, they can be used both as a hardware controller and as a small multimedia, mail, file or web server, not counting the cases of working with thin clients. There remains only the question of managing a single-payer. You can of course give commands directly to the console or control the desktop using the monitor, keyboard and mouse. But, each time the connection for any action of additional equipment creates unnecessary time and labor. There is a way out and its name is Secure shell. The original network protocol used to access the remote console of a *-NIX like system, eventually frolicking into a convenient management and file transfer tool for the Linux OS.
All the information below will mainly refer to the Raspberry PI 3 and older single-board models of the same company.
Secure shell
As already described earlier, SSH is an information transfer protocol used in Linux, which in turn is installed on Raspberry PI 3 under the name Raspbian. And we are talking not only about text data, but also streaming video and audio broadcasting, images, binary files. On full *NIX (Linux) systems, it is used to access on-screen controls and X windows, with the ability to run them on the host machine and display the result on the client machine. Unfortunately, for raspberries, this feature is not available within the standard Raspbian. Nevertheless, the named Debian clone has certain limitations on the functionality of the OS, directly related to the relatively weak hardware stuffing of the single-board. If you still need to access the desktop, then the official documentation of the system recommends taking a closer look at the controls via the VNC protocol, the use of which, like Secure Shell, was originally included in the raspberry.
What distinguishes SSH from the same TELNET is the presence of channel encryption. Using the protocol, you do not have to worry about the security of the transmitted information, since the entire exchange is encoded at a time. One more of the many features embedded in the Secure shell is the compression of transmitted data, which is activated by the corresponding option on the server or client side. The function in some cases allows you to unload the exchange channel via the SSH protocol by reducing the amount of information flow due to compression.
Activation and installation on Raspberry PI
Organization of interface access to the console or SSH protocol capabilities begins with the launch of its server part on Raspberry PI. You can do the named procedure with as many as three methods with a direct connection and one «headless». Of course, the former will initially require direct access to the Raspbian Pi console, with a hardware keyboard and monitor. And in all cases, after the activation parameter is set, you need to reboot the Raspberry Pi to start the service.
So the sequence is:
First
A classic method that works on any Linux using systemd as its init system. Enter in the console:
sudo -s
# enable the service:
sudo systemctl enable ssh
sudo systemctl start ssh
Second
Executed directly from the Raspberry «Preferences» menu in the peculiar menu. start» on the panel, you need to select «Raspberry Pi Configuration». In the window that opens, go to the «Interfaces» tab. In the SSH item, set the adjacent switch to the «Enabled» value. Next, the action is confirmed by clicking «OK» at the bottom of the window.
Third
Activating the server using this method is suitable for cases where the graphical interface in Raspbian is disabled. In the console, you need to type:
sudo raspi-config
After pressing «Enter», upon request, enter the administrator password (for cases when its use is enabled by the rules specified in the /etc/sudoers.d/010_pi-nopasswd file) . By default, the security prompt is disabled.
This will open the text system of the setup menu, in which you need to go to the “Interface Options” section using the keyboard arrow keys and the “Enter” button.
Having entered the named configuration item, you need to move to the SSH section, and then activate the “Enable” at the bottom of the screen, or for some versions of Raspbian “Yes”. Then «Ok». In the subsequent text window that opens with a list of «Finish» settings.
Fourth
Finally, the method works for those cases when there is no physical connection to a single-board computer and there is only a network one. Here you need to make some small changes to the SD card with Raspbian installed. On it you need to find the boot partition. If you put a “clean” OS, then it will be smaller among the two on the map. A file without extension and with any content is placed in the root, named «ssh». Upon detecting it on boot, Raspbian will start a Secure shell server, with a blank security password, and the «pi» user (no quotes).
The function works only until the Raspberry PI is rebooted, and for continued subsequent network access via the protocol, you must directly specify the launch of SSH using one of the methods described earlier. Occurs named due to the deletion of a file in the Raspbian boot partition, after the system detects it and starts the required service once.
On the issue of accessing the named part of Raspbian from Windows. There are no problems in a particular case, due to the use of the FAT32 file system on the boot partition, which is native to older operating systems from Microsoft. The main thing here is the presence of the physical SD card reader itself.
Connection
So, we figured out the moment of activation of the Secure shell on the raspberry. It remains to connect to it via the network and try out the capabilities of the protocol for controlling the Raspberry Pi console.
From Linux or MacOS
Linux or MacOS distributions come standard with the “ssh” utility, which is launched from the terminals of these operating systems. To join a raspberry, you will need to know the IP address of the single-payer itself on the network. So, in order to organize access to the Raspberry Pi ssh, we type in the console:
ssh pi@
The response will be a password request, which is passed by pressing «Enter» by default. Next, the raspberry command line will open, providing access to the single-board console.
In the event that the default username has been changed, the new one is specified on the command line shown earlier, instead of «pi». Although you can make it easier by generally removing everything that is written before “@”, inclusive, from the ssh launch options and enter your login and password (if set) directly into the “login as:” prompt that appears.
From Windows
Control via the Secure shell protocol from Microsoft Windows is performed using a third-party and free program «PuTTY». Finding it is easy enough by entering the name in the Yandex or Google search bar and downloading the archive offered on the pages via the links that appear.
Having opened the program (it is possible from a normal user), to connect, go to the “Session” section. Further, in the window tab on the screen, the selection of the “Connection type” group switch is set to the “SSH” position. Next, the “Host Name (or IP-adress)” field is filled in with the actual address of the raspberry. «Port» should be equal to 22. «Saved session» is entered optionally — then you can use the saved information by two clicks without manual input. The final action in order to connect will be to press the «Open» button, after which the attached console window to the Raspberry PI will already be displayed, prompting you to enter a username.
Some remarks
After configuring access via Secure shell, it is recommended to take care of the security of the connection, even if the raspberry will be used as equipment that is not connected to the internet. As they say, everything must be considered in safety. Sooner or later, a global access to the network will probably be made. And there the organization of safe access depends on elementary forgetfulness. You can simply be too lazy or “run in” and not set a password for login or sudo, leaving everything by default. Accordingly, in other words, by providing a potential attacker with the computing power of the Raspberry PI operating in the local network.
Basic security recommendations, all commands for which are executed in the raspberry console:
- Setting the root password. It is done by one of two methods, through
sudo raspi-config
with the choice of the second item of the program and actions within the instructions on the screen. Another simpler way is to type
sudo passwd root
on the command line, followed by entering the password and confirming it, set in the lines “Enter new UNIX password” and “Retype new UNIX password”: The last command shown in the screenshot is “sudo passwd — unlock root «unlocks the administrator account, which in turn will come in handy later. - Restricting the use of sudo without a password. It is performed by opening the access configuration file for editing with the command
sudo visudo /etc/sudoers.d/010_pi-nopasswd
and replacing the entry in the line with the default user with pi ALL=(ALL) PASSWD: ALL. In the event that a new login has been entered, it is required to specify the given string for it, by entering it after the name entered, used when logging in. - Adding a non-standard user (enters instead of
) and deleting the old one. Here you need to give the following commands:
sudo -s
# add a user. After entering the command, the password will be asked
# for the new user with a line containing "password"
adduser
# give him rights (participation in access groups)
usermod -a -G \
adm,dialout,cdrom,sudo,audio ,video,plugdev,games,users,input,netdev,gpio,i2c,spi
# remove default pi. But there is a nuance - in the documentation for
# Raspberry PI, recommendations are expressed not to do this, since in
# some applications must have it on the system
pkill -u pi
deluser -remove-home pi
If the standard user is not deleted (the last two lines are ignored for input), it is recommended to set a password for it that is different from the default one. The action is performed by typing «sudo passwd pi» in the console.
What else
Separately, I would like to consider the case of connected users via SSH with the ability to compress traffic. On Linux and MacOS, the command modifier with the «-C» option is used to start the compression mode. Accordingly, the access program call takes the form:
ssh -C
The compression method works not only in cases of remote control of the console via SSH, but also when sending files using the Secure shell protocol. This uses the scp command, which is part of the general remote control software package. Compressed format for copying a file from a raspberry:
scp -C pi@
Well, or using ssh back to Raspberry PI:
spc -C
Connection problems
Seemingly connected after setup. Ah, no, sometimes the «Raspberry pi ssh connection refused» error occurs. At the same time, the ping on the network goes to the raspberry. There can be only one reason for this — the Secure shell is not running or is blocked by the firewall of the internal router or the OS itself. You first need to check the status of SSH by connecting to the Raspberry Pi directly, then look at the settings of the client’s operating system in order to search for restrictions on network protocols. Well, if it doesn’t help, deal specifically with router blocking.
Related Video
How to Install Raspbian on Raspberry Pi [Step by Step]
not a toy or limited widget to mess around with.
As with any computer, you’ll need a way to interact with its many components. The most common way to accomplish this is with special software called an operating system.
Deploying an operating system on a standard computer is now a breeze. This used to be a real problem, but now it’s simplified to the point where even novice PC users can do it without the risk of compromising their systems.
However, things are a bit different with the Raspberry Pi. The lack of integrated peripherals (mouse + keyboard) or display can make things even more difficult. But it’s not too bad once you get the hang of it.
card button
Please note that all previous data on the SD card will be erased by the Raspberry Pi Imager. , you cannot access or write to the contents of the SD card by connecting the RPi to a computer.
So you will also have to use an SD card reader and connect it to your computer so you can write the OS to the card. We used an old camera and it worked like a charm. Using a microSD capable phone can also work great.
Installing Raspberry Pi OS (formerly Raspbian) under Windows seems a bit less complicated thanks to the GUIs of the programs we used. Linux users prefer to install it with Terminal (equivalent to CMD on Windows).
How do I install headless Raspbian on an SD card?
This bit can be very useful in case you don’t have an HDMI cable and monitor. Installing a headless Raspberry Pi OS on your RPi will help you interact with it instead of the above mentioned components.
Actually, it’s quite simple and doesn’t require a lot of extra steps. You just follow the standard installation steps we listed above and do the following once completed:
- Refrain from removing the SD card from the reader
- Open the root of the SD card in File Explorer
- Click the View button at the top of the Explorer window
- Make sure that 9028 file name extensions are checked Right click anywhere in the window (do not right click on files)
- Select New > Text Document
- Name the file SSH and delete . txt extension
- Confirm your action
- Disconnect the SD card from the reader
That’s it, now you have enabled SSH on your RPi device which Raspberry Pi OS disables by default. SSH boot sequence will be activated when the OS sees the empty file you created.
Raspberry Pi Won’t Boot?Our guide will help you solve this problem quickly.
So, instead of using peripherals to access the RPi, you can simply interact with it using a Secure Shell (SSH) client, as we’ll explain in the next section.
How to connect to Raspberry Pi?
1.Using peripherals
- Insert new OS SD card into Raspberry Pi
- Purchase a keyboard, mouse, HDMI cable and monitor.
- Connect all of the above to your Raspberry Pi
- Connect the RPi to a power source using the dedicated power port
- Optional: Connect an audio output device if you want the sound to be
- Wait for the Raspberry Pi OS to boot
- Use pi as username and raspberry as password
- Enjoy your new mini pc based on Linux
If you have installed the GUI version of Raspbian, you will easily get comfortable with the system. On the other hand, if you have chosen a simplified non-GUI version controlled by CLI , you will only see lines of text.
This shouldn’t be a problem, but many users are repelled by controlling their PC by entering seemingly complicated text commands. This brings us to the second way to connect to the Raspberry Pi.
2.Using the SSH client
- Download the SSH client (we used Solar Putty).
- Install an SSH client on your computer
- Connect your Raspberry Pi to your router with a Ethernet cable
- Insert a Raspberry Pi OS SD card into your RPi
- Plug your Raspberry Pi into a power source (we used our router’s USB port).
- Go to your router’s gateway address in a browser
- Find the local IP address of the RPi and write it down
- Launch the SSH client and create a new session in it
- Enter the IP address you saved earlier
- Optional: you can skip 6th and 7th steps using raspberry or raspberry. local as address
- Use pi/raspberry as username/password combination
- Specify a name for the credentials (if needed).
- Save the session data and start it (click Create button)
cable
The SSH client version is the CLI version we described above. It has no GUI and you can only interact with your RPi with lines of text. However, once you get the hang of it, you’ll realize that it’s not all that difficult.
Of course, the SSH version is more suitable for advanced users who know a lot about Linux operating systems. Please note that unlike the GUI version, the CLI version is more free and allows you to interfere with what should not be touched.» / >
Therefore, we feel it necessary to warn you: never run commands you are not completely familiar with unless you want to risk the integrity of the Raspberry Pi OS. your Raspberry Pi, a whole world of possibilities opens up before you. You can use your new mini PC (we are talking about size, of course) to host a website, run an email server, or even use it as a VPN server. 0003
If none of these options seem too appealing to you, you might be glad to know that you can turn your Raspberry Pi into a retro gaming console. That’s another story though, and we won’t overwhelm you. details.
Last but not least, you can use mobile apps to access and control your Raspberry Pi if interacting with a PC doesn’t suit you. One such app is RaspController.
Final Thoughts on Installing Raspberry Pi OS
With all of that said, deploying Raspberry Pi OS on your RPi device may not be exactly a walk in the park. However, by following our comprehensive guide, you should be able to get set up regardless of your previous experience .
Please note that despite its size, the RPi is a powerful computer. Therefore, you can use it for a wide range of projects, including but not limited to website hosting, email servers, and even Minecraft servers.
Create a headless torrent server with Deluge On Raspberry Pi
Contents
- 1 Why set up a dedicated torrent server?
- 11 Install client
Deluge service
You can easily download torrents on almost any computer, so why would you want to install a dedicated torrent server anyway? Well, there are some good reasons to do some extra tweaking.
First, you can access it from anywhere on your network. This means that if you want to download something, you don’t have to be on the same computer. You can use your laptop or computer in a completely different room. You can also easily access and manage your torrents from anywhere in the world. You can check if something is downloaded outside of your home or change the priority of your downloads on the fly.
Having a dedicated server also means you can shut down your computers without worrying about stopping the download process. Your server will always be running in the background, even if your computers are turned off or you are not even at home.
The server is also much easier to manage. You don’t have to worry about any other programs on your computer getting in the way, or worse, freezing. The server also limits the number of VPN connections you need to worry about depending on the network situation.
What you need
Surprisingly, you don’t need much here. Everything will be based on your Raspberry Pi.
- Raspberry Pi 3 or better
- External hard drive or network drive
- network cable
- Power cord for pi
- 16GB microSD card Pi. It’s also ideal for setting up the Pi as a torrent server. Go to the Raspberry Pi Foundation download page and get the latest Raspbian Lite. You won’t need a desktop environment on your server. The lighter the better.
Once you have your image, extract it. You want an .img file. Then insert the microSD card into your computer.
If you don’t already have your preferred tool for flashing images to SD cards, there is an excellent cross-platform Etcher app that you can use on any operating system to easily flash your image. Download the correct version for your OS.
Once you have Etcher, open it or install it. The program breaks down the process into three simple steps. In the first section, select your image file. Then find your SD card. When everything looks right, click the button to flash your image. The process will take some time, so be patient.
After Etcher has finished writing the image, there is one more thing you need to do. Install MicroSD on your computer. Look for the «boot» partition. Create an empty file in the base of the «boot» partition called «ssh». This file tells the Pi that SSH access is allowed by default.
Install Raspbian
Unmount the SD card and remove it from the computer. Connect it to the Pi. Connect the Pi directly to your router with an Ethernet cable. Once everything is installed, plug it in.
The Raspberry Pi will take some time to resize its partitions and fill up the SD card. While this is happening, open a web browser and navigate to the router’s web interface. Watch the list of connected devices. Eventually, pi will pop up like «raspberry».
Once you see the Pi on your network, you can use SSH to connect to it. Open OpenSSH and connect to the Pi’s IP address. The username is Pi and the password is «raspberry».
$ ssh [email protected]
Set up a user
You will probably want to create a new Deluge user. This user will run Deluge as a service daemon, and nothing more.
$
sudo groupadd deluge $ sudo -r --home-dir /var/lib/deluge -g deluge deluge
Create this directory and take ownership of your Deluge.
$ sudo mkdir /var/lib/deluge $ chown -R deluge: deluge /var/lib/deluge
Connect to VPN
It’s not necessary to connect to a VPN, but it’s a very good idea. This process won’t be exactly the same, depending on your VPN provider, but it should be fairly similar. Start by installing OpenVPN on Raspbian.
$ sudo apt install openvpn
Then download the OpenVPN configuration files for your VPN. Again, this part will be different, depending on which one you’re using. Most VPN providers provide OpenVPN configuration files either for nothing or as their Linux variant. They usually come in a large .zip file. The files themselves usually have the . ovpn extension.
Find the place you want to use. Depending on your needs, it would be a good idea to choose a server located outside of the US. Copy this file to the OpenVPN system folder and rename it.
$ sudo cp Downloads / config.ovpn /etc/openvpn/client.conf
Once it appears, create a file for authentication. Use a plain text file called auth.txt. On the first line, enter the username for your VPN account. On the second line, add your password. Open the VPN configuration you just copied. Find the line below and match your example.
auth-user-pass auth.txt
This will automatically log you in. Then add the block below just before your certificates. They will handle registering, starting and stopping the service.
/etc/openvpn/openvpn-status.log status log /etc/openvpn/openvpn.log script-security 2 up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf
Save your file and exit. Then restart the service.
$ sudo systemctl restart openvpn $ sudo systemctl start [email protected] $ sudo systemctl enable [email protected]
Create VPN Killswitch
If you’re torrenting behind a VPN, you probably need a reliable switch that will cut your connection off and you’ll lose connection with the VPN. Luckily, this is very easy to do on Linux systems with a firewall. Start by downloading UFW to make it easier to manage your firewall.
$ sudo apt install ufw
Once you have UFW, you can start setting up your rules. Start by disabling UFW.
$ sudo ufw disable
Now tell UFW to block everything by default.
$ sudo ufw default deny incoming $ sudo ufw default deny outgoing
Allow all connections from the computer itself and the local network.
$ sudo ufw allow from 192.168.1.0/24 $ sudo ufw allow from 127.0.0.1
Then allow everything through the VPN. Check the actual interface of your VPN.
$ sudo ufw allows you to login to tun0 $ sudo ufw resolve to tun0
Finally, allow communication with your VPN’s DNS server. Again, check the actual IP in /etc/resolv.conf.
$ sudo allow at 53 $ sudo allow out 53
When you’re done, enable UFW.
$ sudo ufw enable
Install Deluge
You are finally ready to install the stream on your server. So do exactly that.
$ sudo apt install deluged deluge-console
Wait for the installation to complete. It should be pretty fast.
Configure the Deluge Server
To allow connections to your server from other computers, you need to enable remote connections. Go to your Deluge user and open the Deluge console.
$
sudo su deluge flooded $ deluge-console
Then enable remote connections.
config -s allow_remote True
Now stop the Deluge demon. You can do this by looking at the process and killing it.
$ ps aux | Grape Flood $ kill 1923
You need to add a login for your users. The file is in /var/lib/deluge/.config/deluge/auth. Add your user entries in the following order.
Username: Password: 10
The number indicates privileges. 10 makes the user an administrator. When you’re done, save the output.
Create a Deluge Service
Since you want Deluge to start automatically with your Raspberry Pi, you need to write a simple system service. Don’t worry, it’s actually provided in the Deluge documentation. Create a file in /etc/systemd/system/deluged.service. Put the following into it:
[Unit] Description = Deluge Bittorrent Client Daemon Documentation = person: fell asleep After = network-online.target [Service] Type = simple User = flood group = flood UMASK = 007 ExecStart=/usr/bin/deluged -d Reboot = Fail # Time to wait before forcibly stopping. TimeoutStopSec = 300 [Install] WantedBy = multi-user.target
Check this by starting the service and checking the status.
$ sudo systemctl start deluged $ sudo systemctl status removed
If the service is up and running, make the change permanent by enabling the service.
$ sudo systemctl enable deluged
Install the client
Now you can install the Deluge client to connect to your server. Deluge is open source and readily available on multiple platforms.
Windows
Go to the Deluge download page and get the latest release for Windows. Run the exe. The installation process is pretty standard. Feel free to click on the wizard and accept the defaults.
Linux
As you might have guessed, the Linux process is very simple. Just install the client with your package manager.
$ sudo apt install deluge-gtk
Connect to your server
Open Deluge settings by clicking edit? «» Settings «. In the part of the window that opens, there is an «Interface» tab. Press here. At the top of the window is a checkbox that controls Deluge’s classic mode. Uncheck the box to disable it.
Click the Change button again. This time select «Connection Manager». By default, you will see the local IP address. Below the list there are buttons that allow you to add and remove connections. Click the Add button. Enter your server’s IP address in the Hostname field. Leave the port number the same. Then enter the username and password you have set. Click «Add» to finish.
Back in the main Add window, you can now highlight the new entry and click the Connect button at the bottom to connect to the server.
Set up your storage
Before you can download anything, you will need to set up your storage. There are two main options here: an external USB hard drive or a network drive. In any case, it works. You just need something much more than what the Raspberry Pi supports.
USB
Connect a USB stick to the Pi. Then, through your SSH console, look at the available devices.
$ls /dev | grep sd
You should only see the USB stick and possibly your SD card. An SD card will have multiple partitions, while a USB stick will probably only have one. It will look something like this:
SDA sda1 sda2 SDB sdb1
In this case, the external drive is sdb and the partition is sdb1. Create a directory to mount.
$ sudo mkdir /media/external
Now open /etc/fstab in a text editor and create an entry to automatically mount the drive on boot.
/dev/sdb1/media/external ext4 default user exec 0 0
Make sure the path and file system type match your drive. If you’ve ever used a Windows-only drive, the format is probably NTFS and you need to install ntfs-3g on the server.
Do the following to mount the drive.
$ sudo mount -a
Networks
All network drive configurations are different, but if you’re using a Linux NFS drive, you can create a mount directory and add an entry to /etc/fstab.
$ sudo mkdir /media/nfs
Then open fstab and add your drive.
192.168.1.120:/media/share/media/nfs ext4 default, user, exec 0 0
Save and exit. Then mount the drive.
$ sudo mount -a
Configure Deluge
Back in the Deluge client, you can set the download directory for your torrents. Click Edit? «» Settings «. On the first «Downloads» tab, you can specify the download location for the files. Select the location of your newly mounted drive.
Download torrent
To download a torrent from Deluge, click on the plus icon in the upper left corner of the window. A new window will open with various options for adding a torrent. The two most common would be a torrent file and a URL. For a file, you can click on the button to navigate to the location of your torrent file. Click the URL button and paste the URL to add the torrent via URL. The URL function works for magnet links.
The newly added torrent will appear in the main part of the Deluge window. From there, you can track the progress of the torrent. If you want to change the priority of your torrents, you can right-click on them and use the «Queue» option to move them up and down.
Right-clicking on a torrent also gives you many other options. You can set download and upload limits, as well as immediately pause the torrent. There is also an option to delete the torrent. Once the download is complete, you can delete the torrent without deleting the downloaded file. This will stop you from sowing. Of course, you can leave a torrent session and control how those completed torrents are used on the network.
Final Thoughts
You now have a fully functional torrent server set up and ready to download or download as many torrents as you need. The server will run constantly, regardless of your computers. You are also set to work through a VPN for added privacy and security. Enjoy your new torrent experience!
How to Install Ubuntu on Raspberry Pi
Raspberry Pi supports several Linux distributions. In most cases, you just need to flash the system image to an SD card, insert that SD card into your Raspberry Pi, and run it. However, this does not apply to Ubuntu. Installing Ubuntu on a Raspberry Pi used to be a difficult task and it was necessary to create an Ubuntu SSO account before downloading the Ubuntu Core image.
Thankfully, with the release of the Raspberry Pi Imager tool, installing Ubuntu on your Raspberry Pi is now very easy. In this article, you will learn how to install an Ubuntu image on a Raspberry Pi.
Introducing the Raspberry Pi Imager
In March 2020, the official Raspberry Pi Foundation released the Raspberry Pi Imager tool. This is a simple tool that downloads a list of different operating systems that you can use with your Raspberry Pi.
Simply select an image from the list and the Raspberry Pi Imager will read the appropriate files from the Foundation’s website and write them directly to your SD card without worrying about finding the correct system image and downloading it to your hard drive.
Let’s see how you can use this tool to install Ubuntu on your Raspberry Pi.
Install Ubuntu with Raspberry Pi Imager
If you haven’t already, go to the Raspberry Pi Foundation website and download the correct Raspberry Pi Imager for your operating system.
After installing the Raspberry Pi Imager:
1. Insert the SD card into your laptop or computer.
2. Launch the Raspberry Pi Imager application.
3. Click Select OS. The Imager will now retrieve and display information about the various operating systems that are compatible with the Raspberry Pi.
4. Since you want to install Ubuntu, select «Ubuntu».
You can now choose from the latest Ubuntu LTS (long term support) server images or Ubuntu Core images. At the time of writing, the following images were available for the Raspberry Pi:
- Ubuntu 20.04 LTS. 32-bit server OS for armhf architectures.
- Ubuntu 20.04 LTS. 64-bit server OS for arm64 architectures.
- Ubuntu Core 18. Ubuntu Core 18 32-bit IoT OS for armhf architectures.
- Ubuntu Core 18. Ubuntu Core 18 64-bit IoT OS for arm64 architectures.
Make sure you select the image that is compatible with your specific Raspberry Pi model.
5. Once you’ve made your selection, click «Select SD Card» and select the SD card you want to burn your system image to.
6. Now all that’s left is to click «Burn» and wait for the Raspberry Pi Imager to write the system image to your SD card.
Set up Ubuntu to automatically connect to Wi-Fi
Then edit the Ubuntu system image on the SD card so that the Pi automatically connects to the Wi-Fi network:
1. Make sure the SD card is inserted in your laptop or computer . Launch the file manager app and navigate to the SD card folder.
2. Open the «system-boot» section, as this contains the configuration files that will be loaded when the Raspberry Pi boots.
3. Open the «network-config» file in a text editor.
4. Locate the «wifis» section and uncomment everything inside that section by deleting the «#» at the beginning of each line.
The Wi-Fi section should now look something like the image below.
You will need to update «Access Points» to include the name of your Wi-Fi network. If this name contains spaces, make sure you enclose it in quotation marks, for example:
Then replace «S3kr1t» with the password of your own Wi-Fi network.
Save this file and safely remove the SD card from your laptop or computer.
Now every time you boot up your Raspberry Pi, it will automatically connect to the network.
Using Ubuntu on Raspberry Pi
Connect a monitor and keyboard to your Raspberry Pi and turn it on. On the login screen, log in with the default Ubuntu account: «ubuntu» for username and password.
Since this login is public by default, you will be prompted to change the password to a more secure one. Follow the instructions on the screen to create a new password.
Consider installing a desktop
By now, you have noticed that Ubuntu does not have a graphical user interface (GUI), so you can only interact with the Raspberry Pi from the command line.
If you prefer to interact with your Pi in a desktop environment, you can install multiple desktops:
First, update your Raspberry Pi:
Then you can install your preferred desktop environment. For example:
After you have installed the desktop environment, reboot the Pi with the following command:
When your Raspberry Pi boots, the desktop environment will be ready to use.
Set up a headless Raspberry Pi
If you prefer to run your Pi headless, you might want to SSH into it.
To communicate via SSH, you need to know the IP address of your Raspberry Pi. If you don’t know your Pi’s IP address, there are several ways to get this information for a headless Raspberry Pi:0003
- You can view information about all devices connected to your network by logging into your router’s configuration page. In the browser address bar, enter your router’s IP address and log in to your account.
Each router is different, but if you explore the various menus and sections, you should be able to find an entry for all the devices connected to your router. Find your Raspberry Pi in the list, click on it and you should be able to access the Pi’s IP address.
- Fing for Android and iOS
Fing is a free network scanning app available for Android and iOS.
Install this application on your smartphone and select «Search for Devices -> Devices». You should now have a list of devices that are currently connected to your network.
Find your Raspberry Pi and write down its IP address.
Connecting via SSH
Once you have your Raspberry Pi’s IP address, you are ready to connect via SSH.
On your computer, open a Terminal and run the following command:
When prompted, enter the default Ubuntu password: «ubuntu».
You are now connected to your Raspberry Pi and can start entering commands via SSH.
Summary
As you can see, installing Ubuntu on your Raspberry Pi is easy with the new Imager app. If you’re not interested in Ubuntu, you can also install FydeOS on your Raspberry Pi, or just turn your Raspberry Pi into a Wi-Fi bridge.
Connecting Raspberry Pi to Azure IoT Hub in the Cloud (Node.js)
- Article
- Reading takes 11 minutes
This tutorial describes how to get started with your Raspberry Pi device running Raspberry Pi OS. You’ll also learn how you can easily connect devices to the cloud using the Azure IoT Hub. Samples for Windows 10 IoT Core are provided in the Windows Dev Center.
No start dial? Use the online Raspberry Pi simulator. Or buy a new set here.
What to do
-
Create an IoT hub.
-
Let’s register a device for the Pi in the IoT Hub.
-
Set up Raspberry Pi.
-
We will run a sample Pi application to send data to the IoT Hub.
What you will learn
-
How to create an Azure IoT Hub and get a new device connection string.
-
How to connect Pi to BME280 sensor.
-
How to collect sensor data by running the example app on the Pi.
-
How to send sensor data to IoT Hub.
What you need
-
Raspberry Pi 2 or Raspberry Pi 3 board.
-
Azure Subscription. If you don’t already have an Azure subscription, create a free account before you get started.
-
Monitor, USB keyboard and mouse connected to the Pi.
-
PC or Mac running Windows or Linux.
-
Internet connection.
-
16 GB microSD card or more.
-
USB-SD adapter or microSD card for writing an operating system image to a microSD card.
-
Power supply 5 V 2 A with Micro USB cable approx. 1.8 meters long.
The following are optional components.
-
Adafruit BME280 temperature, pressure and humidity sensor assembly.
-
Mounting plate.
-
6 fiber optic cables with a connector on one end and a socket on the other.
-
LED indicator 10 mm with ambient light.
Note
If you don’t have additional items, you can use simulated sensors.
Create an IoT hub
This section describes how to create an IoT hub using the Azure portal.
-
Sign in to the Azure portal.
-
On the Azure home page, click the + Create resource button.
-
From menu Category select IoT and IoT Hub .
-
Complete the following fields on the tab Basic Information .
-
Subscription : Select the desired subscription for the hub.
-
Resource group . Select a resource group or create a new one. To create a new one, click New and enter the desired name. To select an existing resource group, click it. For more information about resource groups, see Managing resource groups in Azure Resource Manager.
-
IoT hub name . Enter a name for the hub. This name must be globally unique and contain between 3 and 50 alphanumeric characters. The name may also contain a dash character (
'-'
). -
Region . Choose the region closest to you where the center will be located. Some features, such as IoT Hub device flows, are only available in certain regions. For features with these restrictions, you must select one of the supported regions.
Important!
Because the IoT hub will be publicly available as a DNS endpoint, make sure it doesn’t contain sensitive or personal information in its name.
-
-
When done, select Next: Networking to continue creating the hub.
Select the endpoints that devices can use to connect to the IoT hub. For our example, accept the default parameter — General access .
-
When done, select Next: Management to continue creating the center.
Accept the default settings. If necessary, you can change any of the following fields:
-
Price and scale category . The category you choose depends on the number of features you need and the messages you send every day with your solution. You can use the Free tier for testing and evaluation. It allows you to connect 500 devices to the center and send up to 8,000 messages per day. You can create one IoT Hub at the Free tier per Azure subscription. For more information about other tier options, see Choose the right IoT hub tier for your solution.
If you are using the Quick Start Guide, select the Free tier.
-
IoT Hub Units . The allowable number of messages per unit per day depends on the price category of the center. For example, if the center needs to support 700,000 incoming messages, two S1 units should be selected.
-
Microsoft Defender for IoT . Turn on Defender for an extra layer of protection for IoT and your devices. This setting is not available for hubs in the Free tier. Learn more about security best practices for the Defender for IoT IoT Hub.
-
Role Based Access Control . This property defines the method to control access to the IoT Hub. Allow sharing policies or select only role-based access control. For more information, see Manage access to IoT Hub with Azure Active Directory.
-
Device to Cloud sections . This property ties messages sent from the device to the cloud to the number of concurrent readers of those messages. For most hubs, four partitions are sufficient.
-
-
When done, select Next: Tags to go to the next screen.
Tags are name-value pairs. You can assign the same tag to multiple resources and resource groups to categorize them and combine accounts. No tags will be added to this document. For more information, see Use tags to organize resources in Azure.
-
When done select Next: View and create to view the selected options. A screen similar to the following will be displayed with only the values you set when creating the center.
-
Click Create to begin deploying the center. The deployment will take several minutes while the hub is being created. When the deployment is complete, select Go to resource to open the new hub.
New device registration in IoT Hub
In this section, you will create a device identity in the IoT Hub identity registry. A device can connect to the hub only if there is a corresponding entry in the identity registry. For more information, see the IoT Hub Developer Guide.
-
In the IoT Hub navigation menu, select Devices and then click Add device to add the device to the IoT Hub.
-
Under Create device , enter a name for the new device, such as myDeviceId , and click Save . This will create a device identity for your IoT Hub. Do not uncheck the Automatically generate keys check box so that the primary and secondary keys are generated automatically.
Important!
The device ID may appear in logs collected for customer support and troubleshooting, so do not use sensitive information when naming it.
-
Once the device has been created, open it from the area list Devices . Copy main connection string . This connection string is used by the device code to communicate with the hub.
Keys and connection strings are masked by default because they are sensitive information. If you click on the eye icon, they will be displayed. To copy them using the copy button, they do not need to be displayed.
Note
The Identity Registry in IoT Hub stores only the device IDs needed to securely access IoT Hub. This registry stores device IDs and keys, which are used as security credentials, and an enable or disable flag that allows you to disable access for an individual device. If your app needs to store other device-specific metadata, you should use app-specific storage. For more information, see the Developer Guide for IoT Hub.
Raspberry Pi setup
Raspberry Pi OS installation
Prepare a microSD card to install the Raspberry Pi OS image.
-
Download Raspberry Pi OS with desktop.
a. Raspberry Pi OS with desktop (as a ZIP file).
b. Extract the Raspberry Pi OS with the desktop image to a folder on your computer.
-
Install Raspberry Pi OS from Desktop to microSD card.
a. Download and install the Etcher utility to write data to SD cards.
b. Launch Etcher and select the Raspberry Pi OS with the desktop image extracted in step 1.
c. Select a microSD card reader. Etcher may already have the correct reader selected.
d. Click Flash (Switch) to install Raspberry Pi OS with desktop on the microSD card.
e) When installation is complete, remove the microSD card from the computer. It is safe to remove the microSD card directly, as the Etcher software will automatically eject or disable the microSD card upon completion.
e) Insert a microSD card into the Pi.
Enabling SSH and I2C
-
Connect the Pi to a monitor, keyboard and mouse.
-
Start Pi and login to Raspberry Pi OS with username
pi
and passwordraspberry
. -
Click the Raspberry icon and select > Settings > Raspberry Pi Configuration .
-
In tab Interfaces , set SSH and I2C to Enable , and then click OK .
Interface Description SSH Secure Shell (SSH) is used to remotely connect to a Raspberry Pi using a remote command line. This is the preferred method for issuing remote commands to the Raspberry Pi and is described in this document. I2C I2C is a communication protocol used to communicate with equipment such as sensors. This interface is required to interact with the physical sensors described in this article. If you don’t have physical sensors and want to use simulated sensor data from your Raspberry Pi, you can disable parameter I2C .
note
For information on how to enable SSH and I2C, see additional help documents at raspberrypi.org and Adafruit.com.
Connecting the sensor to the Pi
Connect the BME280 LED and sensor to the Pi using the circuit board and fiber optic cables as shown below. If you do not have this sensor, skip this section.
The BME280 can collect temperature and humidity data. The LED indicator flashes when the device sends a message to the cloud.
To connect the sensor leads, use the following cables:
Start (sensor and LED indicator) End (board) Cable color VDD (5G output) 3. 3V PWR (pin 1) White cable GND (pin 7G) GND (pin 6) Brown cable SDI (10G output) I2C1 SDA (pin 3) Red cable SCK (8G output) I2C1 SCL (pin 5) Orange cable LED VDD (pin 18F) GPIO 24 (pin 18) White cable LED GND (pin 17F) GND (pin 20) Black cable Click to view Raspberry Pi 2 and 3 pin mapping for reference.
After successfully connecting the BME280 sensor to the Raspberry Pi, the circuit should look like the image below.
Connecting the Pi to the network
Turn on the Pi using the Micro USB cable and power supply. Connect your Pi to a wired network using an Ethernet cable, or follow the instructions from the Raspberry Pi Foundation to connect your Pi to a wireless network. After successfully connecting the Pi to the network, you need to remember the IP address of the Pi device.
Note
Make sure the Pi is connected to the same network as the computer. For example, if the computer is connected to a wireless network and the Pi board is connected to a wired network, then the IP address may not appear in the devdisco output.
Running the sample app on the Pi
Cloning the sample app and installing the prerequisite packages
-
Use one of the following SSH clients to connect to the Raspberry Pi from the host computer:
Windows users
a. Download and install PuTTY for Windows.
b. Copy the Pi’s IP address and paste it into the hostname (or IP address) field, and then select the SSH connection type.
MAC and Ubuntu users
Use the SSH client built into Ubuntu or macOS. You may need to run
ssh pi@
to connect your Pi using SSH.Note
The default username is
pi
and the password israspberry
. -
Install Node.js and NPM on the Pi.
Check Node.js versions first.
node-v
If you’re using a version below 10.x, or if you don’t have Node.js installed on your Pi, install the latest version.
curl -sSL https://deb.nodesource.com/setup_16.x | sudo -E bash sudo apt-get -y install nodejs
-
Clone the sample application.
git clone https://github.com/Azure-Samples/azure-iot-samples-node.git
-
Install all sample packages, including Azure IoT Device SDK, BME280 Sensor Library, and Wiring Pi Library.
cd azure-iot-samples-node/iot-hub/Tutorials/RaspberryPiApp npm install
Note
Depending on your network connection, the installation process may take several minutes.
Configuring the sample application
-
Open the configuration file by running the following command:
nanoconfig.json
Two items can be configured in this file. The first one is
interval
. It defines the time (in milliseconds) between sending two messages to the cloud. Second —simulatedData
. It represents a boolean value that determines whether the simulated sensor data will be used.If you do not have sensor , set parameter
simulatedData
totrue
to have the sample application create and use simulated sensor data.Note. The i2c address used in this tutorial is 0x77 by default. Depending on your configuration, this could also be 0x76: if you encounter an i2c error, try changing the value to 118 and see if that improves performance. To find out which address is used by the sensor, run command
sudo i2cdetect -y 1
in a shell on the Raspberry Pi. -
Save your changes and close the window by pressing CTRL+O > ENTER > CTRL+X.
Running the sample app
Run the sample app by running the following command:
sudo node index. js '
' Note
Be sure to copy and paste the device connection string, enclosing it in single quotes.
The following results should be displayed containing sensor data and messages that are sent to the IoT Hub.
Reading messages received by the Hub
One tool for monitoring messages received by the IoT hub from your device is the Azure IoT Tools extension for Visual Studio Code. For more information, see Messaging between a device and IoT Hub using the Azure IoT Tools extension for Visual Studio Code.
To learn more about other ways to process data sent by the device, go to the next section.
Cleaning up resources
The resources created in this section can be used with other tutorials and quickstarts in this document set. If you plan to continue with subsequent quickstarts or tutorials, do not delete the resources you have created. If you don’t plan to continue, delete any resources you created by doing the following in the Azure portal.