Basic Setup of Ubuntu Server 21.10 on Raspberry Pi4

This is a guide for a secure installation of 64-bit Ubuntu Server 21.10 on Raspberry Pi 4.

Table of Contents

    1. Upgrade Raspberry Pi4 Bootloader Firmware

    If you are using an older Pi4 then it might have an old bootloader. There were some nice firmware updates since the fall of 2020 to support USB SSD boot. When I start a new project I like to make sure the Pi has the latest stable version of the firmware.
    See this guide for upgrading bootloader.

    2a. Ubuntu Installation on SD card

    1. Download & Extract Ubuntu Server 21.10 64-bit Version
    2. Download & Install Raspberry Pi Imager v1.6 Software
    3. Write Ubuntu Image to SD card
    4. Insert SD card into Raspberry Pi

    2b. Ubuntu Installation on USB SSD

    Instead of running from SD card you can use an external USB SSD. See this guide for Booting from USB SSD.

    3. Ubuntu Setup with Headless Operation + Ethernet Connection

    1. Power up Raspberry Pi
    2. Wait a couple of minutes for initial bootup
    3. Determine local IP address of Raspberry Pi using your favorite method
      • login into your router and check the DHCP client list. Default hostname of the Pi is ubuntu
      • Fing is nice application on Android for scanning devices on your network
    4. Open SSH connection using your favorite application(example: putty)
      • Default login
        • user: ubuntu
        • password: ubuntu
      • On first login you will be asked to change default password
      • SSH session will be automatically closed as soon as password is changed
    5. Login with new password
    6. Switch to root environment
      • sudo -i
    7. Update Time Zone. Configure according to this guide
      • To get list of available timeszones:timedatectl list-timezones
      • Example Configure Timezone timedatectl set-timezone America/Edmonton
    8. At this point Ubuntu will immediately start auto updating which can interfere with other other packages that you may be installing next. I have found that the best thing is to just let the updates complete in the background before moving to the next steps. This could maybe take 30 minutes or more. I will just use top command to see when the CPU activity is back down to idle level.
    9. Obtain latest versions of installed packages(autoupdates in the background should have everything updated but you can check to make sure)
      • apt update
    10. update all installed packages
      • apt upgrade
    11. Disable auto updates(Optional). Open 20auto-upgrades file.
      • nano /etc/apt/apt.conf.d/20auto-upgrades
    12. Replace values in file with the following:
    APT::Periodic::Update-Package-Lists "0";
    APT::Periodic::Download-Upgradeable-Packages "0";
    APT::Periodic::AutocleanInterval "0";
    APT::Periodic::Unattended-Upgrade "0";
    1. Configure basic firewall to close all ports except for SSH
      • Use this if you want SSH access from outside your local network:
        • ufw allow 22
      • Use this if you want to limit SSH access to your local network:
        • ufw allow from to any port 22
      • Enable Firewall
        • ufw enable
      • Note: use ufw show added to see rules when ufw is not enabled
      • Note: use ufw status to see active rules when ufw is enabled
    2. Create new user and add to sudo group. Replace friends with your own username.
      • adduser friends && usermod -aG sudo friends
      • exit
      • exit
    3. Close SSH connection and login using new user
    4. Switch to root environment
      • sudo -i
    5. Install userland vcgencmd tools(optional)
      • apt install libraspberrypi-bin
    6. Add user to video group. Replace friends with your own username.
      • usermod -aG video friends
    7. Delete ubuntu user info
      • deluser ubuntu
      • rm -rf /home/ubuntu
      • `exit
    8. Find MAC address(optional) . This can be useful if you need to configure port forwarding in your router.
      • cat /sys/class/net/eth0/address
    9. Clear terminal history
      • history -c && history -w
    10. Reboot with new settings
      • sudo reboot