Basic Setup of Ubuntu Server 21.04 on Raspberry Pi4

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

Table of Contents

    1. Ubuntu Installation on SD card

    1. Download & Extract Ubuntu Server 21.04 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

    2. 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
      • Configure Timezone timedatectl set-timezone America/Edmonton
    8. Obtain latest versions of installed packages
      • apt update
    9. update all installed packages
      • apt upgrade
    10. Disable auto updates(Optional). Open 20auto-upgrades file.
      • nano /etc/apt/apt.conf.d/20auto-upgrades
    11. Replacing 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
      • 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. Add new user. Replace friends with your user.
      • 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. Delete ubuntu user info
      • deluser ubuntu
      • rm -rf /home/ubuntu
      • exit
    6. Find MAC address(optional). This can be usefull for some applications if you need to configure port forwarding. The MAC address will be after the line starting with ether
      • ip address show
    7. Clear terminal history
      • history -c && history -w
    8. Reboot with new settings
      • reboot