DEV Community

El Bruno
El Bruno

Posted on • Originally published at elbruno.com on

#RaspberryPi โ€“ 1st setup no monitor ๐Ÿ“บ: Wifi ๐Ÿ“ถ auto connect, SSH, rename, update, docker ๐Ÿณ, rust and more! Update 2023-Jan-04

Latest version 2023-Jan-05 here

Content

  1. Create SD card using Raspberry Pi Imager
  2. Configure Wireless connection (if needed)
  3. Enable SSH (if needed)
  4. Find the IP address in your network
  5. Access via SSH
  6. Change Password (if needed)
  7. Rename the device (if needed)
  8. Expand FileSystem
  9. Update the device
  10. Install Docker
  11. Setup SSH password-less access to the Raspberry Pi
  12. Setup password-less access to remote work with docker ๐Ÿณ
  13. Run Docker ๐Ÿณ commands without sudo
  14. Install Rust

Hi!

Letโ€™s start installing the latest Raspberry Pi OS image in an SD card. Next steps will be focus on how to access and control remotely your device you may want to follow this steps.

raspberry Pi Images install SO

This tutorial and tips works for Raspberry Pi 3, 4 and Zero.

The version 1.6 of Raspberry Pi Imager includes a new feature that allows to

  • Define HostName
  • Enable SSH
  • Configure Wifi
  • Set locale

Directly from the tool pressing the [Config] button

raspberry pi imager config

_ Note: Open the setting using this button is new in the latest Raspverry Pi imager version._

We can define this settings on the tool screen.

Iโ€™ll leave the old-school standard methods below just as a reference.

Configure Wireless connection (if needed)

In the SD Card, you need to create a file named [wpa_supplicant.conf] in the root of the SD card with the following information:


country=ca
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid=" Your WiFi SSID"
 psk="You amazing password"
}

Enter fullscreen mode Exit fullscreen mode

The file content is very straight forward to understand. Main values to complete are [ssid] and [psk].

Once you put the SD card in the device and start the device, it will automatically connect to the configured WiFi.

Enable SSH (if needed)

If you also want to enable SSH, you need to create a blank file named [ssh] to the main partition.

Once you put the SD card in the device and start the device, it will automatically enable the SSH service.

So, you need to create and copy 2 files to the root of your SD card

  • wpa_supplicant.conf
  • ssh

Find the IP address in your network

And thatโ€™s it, your Raspberry Pi will be connected to the Wifi and with SSH enabled. At this moment we can use a tool like AngryIp (see references) to detect the new device in the network

My new device IP is: 192.168.1.246

Iโ€™m trying to avoid Java updates, and even install java, so lately I use a mobile app: Fing, and after a search the results are nicer.

Access via SSH

I used to like Putty to connect to my device, however during the past months Iโ€™ve been using Windows Terminal and Powershell. In order to access the device I need to execute the command


ssh user@deviceaddress

Enter fullscreen mode Exit fullscreen mode

and my data is

  • user: pi
  • ip: 192.168.1.246
  • password: raspberry

You can now start working with your Raspberry Pi !

If you get a SSH error message similar to this one


@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
---
Host key verification failed.

Enter fullscreen mode Exit fullscreen mode

You need to run this command to fix the host hey.


# ssh-keygen -R <host>
ssh-keygen -R 192.168.1.247

Enter fullscreen mode Exit fullscreen mode

_ Important: the default password is raspberry, please follow next step!_

Change Password (if needed)

The default password for the device is โ€œraspberryโ€, and as usual, itโ€™s recommended to change it. In order to do this, in the ssh terminal, letโ€™s access to the device configuration


sudo raspi-config

Enter fullscreen mode Exit fullscreen mode

This will open the configuration for the device.

raspi config main menu

Option number 1 will allow us to change the password.

Rename the device (if needed)

In the same section we can change the Host Name.

And define the new name for the Raspberry Pi device.

Expand FileSystem

Another important option in the configuration is to expand the SD disk.In the same configuration screen, select

  • 6. Advanced Options
  • Expand File System

raspi config advanced options

Now we need to reboot and after the reboot the file system should have been expanded to include all available space on your micro-SD card. Reboot with the command


sudo reboot

Enter fullscreen mode Exit fullscreen mode

Update the device

There are 2 ways to update the device, using commands and using raspi-config.

  • In the Raspi Config main menu, the option 8 will launch the update commands.
  • If you prefer to manually type an update command, this one works for me

sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'

Enter fullscreen mode Exit fullscreen mode

updates complete

Install Docker

The information is available from the Official Docker Documentation


curl -fsSL https://get.docker.com -o get-docker.sh

sudo sh get-docker.sh

Enter fullscreen mode Exit fullscreen mode

And then, a simple check for the docker version with the command


docker version

Enter fullscreen mode Exit fullscreen mode

Setup ssh password-less access to the Raspberry Pi

The main resource is an official one fro the Raspberry Pi org: Passwordless SSH access. Here is a quick resume for Windows 11 users. First letโ€™s run this command


ls ~/.ssh

Enter fullscreen mode Exit fullscreen mode

I already keys on my computer, so I found id_sa and id_rsa.pub.

raspberry pi ssh keys

Now, letโ€™s copy them to the device. For this this command:


cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'

Enter fullscreen mode Exit fullscreen mode

And thatโ€™s it! Now we can ssh the Raspberry Pi without password.

_ Disclaimer: you know that this is not a very secure practice?_

Setup SSH password-less access to remote work with docker ๐Ÿณ

Once we finished ssh password-less access, we can easily configure a TCP-enabled Docker.

I followed the next steps. First, letโ€™s edit docker.service with the command:


sudo nano /lib/systemd/system/docker.service

Enter fullscreen mode Exit fullscreen mode

And add [-H tcp://0.0.0.0:2375] at [ExecStart] section:

raspberry pi ssh password less docker

And restart the device or just the needed services

  • run sudo systemctl daemon-reload
  • run sudo systemctl restart docker

Run Docker ๐Ÿณ commands without sudo

Now letโ€™s upgrade our docker commands, so we can run them without sudo. Just run this commands


sudo groupadd docker
sudo gpasswd -a $USER docker

Enter fullscreen mode Exit fullscreen mode

And also restart the service:


sudo service docker restart

Enter fullscreen mode Exit fullscreen mode

Install Rust

To install Rust run the following in your terminal, then follow the on-screen instructions.


curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Enter fullscreen mode Exit fullscreen mode

These are the options, Iโ€™ll go with the default one

rust install options

After a couple of minutes, we have rust installed !

rust installed

I closed my terminal and opened again, and I can test the rust and cargo version with the commands


rustc --version
cargo --version

Enter fullscreen mode Exit fullscreen mode

displaying rust and cargo version in the terminal

I can even create a new app using cargo, edit the main file and run it!

I can even create a new app using cargo, edit the main file and run it!

Rust is working fine !

Conclusion

And thatโ€™s it, we have our device updated and running with the latest software versions and we didnโ€™t use a monitor! Iโ€™ll update this post frequently to make it relevant with my personal best practices.

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.


My posts on Raspberry Pi โšก๐Ÿฒ โšก

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

Top comments (0)