Setting up a Raspberry Pi can be a fun and rewarding experience, but it often requires a monitor, keyboard, and mouse. For those who prefer the command line or lack these peripherals, setting up your Raspberry Pi headlessly – without a visual interface – is a viable and convenient option. This guide will walk you through the process, enabling you to remotely access and configure your Raspberry Pi using only your computer and an Ethernet cable.
Raspberry Pi 5 Model B (or similar model with an Ethernet port)Power Supply (for your Raspberry Pi)Micro SD Card (≥ 8GB recommended)Card Reader (that supports Micro SD cards)Computer or Laptop (with Ubuntu operating system and an Ethernet port)Ethernet Cable (with RJ45 connector)Internet Access (Recommended for remote access and updates)
Option 1 - Latest Version: Download the latest Raspberry Pi Imager from the official Raspberry Pi website or use the following command in your Ubuntu terminal:wget https://downloads.raspberrypi.org/imager/imager_latest_amd64.deb sudo apt install ./imager_latest_amd64.deb rm -rf imager_latest_amd64.deb
Option 2 - Specific Version: If you prefer a specific version, navigate to the official Raspberry Pi GitHub repository and download the desired version. Then, use the following command, replacing <num> with the desired version number:wget https://github.com/raspberrypi/rpi-imager/releases/download/v<num>/rpi-imager_<num>_amd64.deb sudo apt install ./rpi-imager_<num>_amd64.deb rm -rf rpi-imager_<num>_amd64.deb
Choose Your Raspberry Pi: Select the appropriate device based on your Raspberry Pi model from the list of supported devices.Select Operating System: For headless setups, choose "Raspberry Pi OS Lite (64-bit)". This version provides a minimal environment without a graphical interface.Select Storage Device: Select your Micro SD card as the storage device for writing the operating system.Click "Next" and Choose "Edit Settings": This opens the customization settings for your Raspberry Pi OS.Configure Hostname, Username, and Password: Enable the "Set hostname" option and optionally set a custom hostname. You can leave the default "raspberrypi" if desired. Enable the "Set username and password" option and provide a desired username and password. For instance, use "pi" for both the username and password.Enable SSH: Navigate to the "Services" menu and check the "Enable SSH" option. This enables remote access to your Raspberry Pi via Secure Shell (SSH).Start Writing: Click "YES" twice to confirm your settings, and Raspberry Pi Imager will begin writing the operating system to your Micro SD card.Wait for Completion: Allow the process to finish. Once complete, safely eject the Micro SD card from your computer.
Power Up and Connect: Power on your Raspberry Pi and connect it to your laptop using an Ethernet cable.Configure Network Settings: Go to your Ubuntu network settings, select "Wired Connection," and open the "Wired Settings."Click the gear icon next to your current Wired profile. Remove the existing profile by clicking "Remove Connection Profile." Click the "+" icon to create a new connection profile, naming it "Raspberry Pi" or something similar. Navigate to the "IPv4" menu, select "Shared to other computers" under "IPv4 Method." This enables your laptop to act as a DHCP server, assigning an IP address to your Raspberry Pi. Click "Add" to save the profile.
Connect via SSH: Open your terminal and use the following command, replacing <username> and <hostname> with the values you configured in Raspberry Pi Imager. In our example, this would be:ssh pi@raspberrypi.local
Type "yes" and press Enter to add the Raspberry Pi's key fingerprint to your known hosts list. Enter your password and press Enter. You should now be connected to your Raspberry Pi via SSH over Ethernet.
Open NetworkManager Text User Interface: Open your terminal and execute the following command:sudo nmtui
Select Wi-Fi Network: Use the arrow keys to navigate and select "Activate a connection." Choose your desired Wi-Fi network and press Enter to enter the password.Enter Password: Type your Wi-Fi password and press Enter. The Raspberry Pi should now connect to your Wi-Fi network.Verify Internet Connectivity: Return to your terminal and try pinging Google's DNS server (8.8.8.8):ping 8.8.8.8
If you receive ping replies, your Raspberry Pi is successfully connected to the internet.
hostname -I
Log Out and Disconnect Ethernet: In your SSH session, run logout to disconnect from your Raspberry Pi. Unplug the Ethernet cable.Connect via SSH over Wi-Fi: Now, use the following command, replacing <ip-address> with the Wi-Fi IP address you previously noted:ssh pi@<ip-address>
If you encounter a "Warning: Remote Host Identification has Changed" message, run the following command to remove the old key fingerprint: ssh-keygen -R <ip-address>
Try connecting again using the same ssh command. You should now be connected to your Raspberry Pi via SSH over Wi-Fi.
sudo apt update && sudo apt upgrade
0 comments:
Post a Comment