Installing Ubuntu Server on the Raspberry Pi?

The Raspberry Pi is a versatile, low-cost device that can function as a full-fledged Linux server. Ubuntu Server is one of the most popular server operating systems, providing a stable and secure platform for hosting applications and services. Installing Ubuntu Server on a Raspberry Pi is an excellent way to learn server management skills and build DIY projects.

Installing Ubuntu Server on the Raspberry Pi?

This guide covers all the steps for installing Ubuntu Server 20.04.3 LTS on a Raspberry Pi 4. Additional optimizations like setting up SSH access, user accounts, and firewall rules are also provided to enhance security and usability after initial installation.


Before you begin, make sure you have the following:

  • A Raspberry Pi 4 (models with 2GB+ RAM recommended). Other Pi models may also work but have not been tested.
  • A microSD card with at least 16GB capacity, Class 10 performance rating preferred.
  • A 5.1V USB-C power supply that can provide at least 3.0A current.
  • A computer to prepare the SD card image.
  • Network access to download Ubuntu Server image.
  • A wired network connection (recommended) or Wi-Fi dongle for wireless access.
  • Optional: A heat sink for the Pi processor to allow sustained high performance.

Downloading the Ubuntu Server Image

  1. Go to the Ubuntu Pi releases page and download the latest 64-bit Ubuntu Server for Raspberry Pi (arm64) image. At time of writing, this is Ubuntu Server 20.04.3 LTS.
  2. Download and install Raspberry Pi Imager to the computer you will use to prepare the SD card.
  3. Connect your microSD card and launch Raspberry Pi Imager.
  4. Click the CHOOSE OS button and select the Use custom option.
  5. Browse to and select the Ubuntu Server .img file you downloaded earlier.
  6. Select your connected SD card drive under SD Card. Double check you have selected the correct drive to avoid overwriting data.
  7. Review the settings summary then click WRITE to flash the image onto the card. This will take a few minutes to complete.

First Boot and Initial Setup

With the SD card prepared, you can now boot your Pi from it and begin configuring Ubuntu Server:

  1. Insert the SD card to your Pi and connect ethernet/Wi-Fi adapter if using wireless connectivity. 
  2. Power on the Pi wait for Ubuntu Server to boot – this takes 1-2 minutes on first launch as it expands the filesystem. 
  3. Find the IP address assigned to your Pi from the DHCP server on your network or using an IP scanner tool. 
  4. SSH into your Pi using the ubuntu account and provided password:

`ssh ubuntu@<ip-address>`

When prompted, change the ubuntu password using:

Optionally, create additional user accounts replacing new user:

`adduser new user`

Reboot to complete account setup using:

  1. `reboot` 
  2. After rebooting, SSH back in using your new password or user account.

Your basic Ubuntu Server setup on Raspberry Pi is now complete!

Enhancing Security

To protect Ubuntu Server from unauthorized access, follow these key security steps:

Change SSH Port

  1. Edit SSH daemon config:

`sudo nano /etc/ssh/sshd_config`

Change the port value from 22 to any unused port between 1025-65525.

Save changes and restart the SSH service:

  1. `sudo systemctl restart sshd` 
  2. SSH port is now changed, connect using -p <port> 

Setup Uncomplicated Firewall

  1. Check UFW status which should be inactive by default: 

`sudo ufw status`

Allow SSH port using custom port number from previous step:

`sudo ufw allow <port>/tcp`

Enable firewall marking allowed ports as in:

`sudo ufw enable`

Verify active firewall rules:

  1. `sudo ufw status` 

The SSH port is now stealth protected by the firewall!

Add Public Key Authentication (Recommended)

For enhanced login security, SSH public key authentication can be used instead of password login:

  1. On your main computer, generate a keypair: 

`ssh-keygen -t rsa -b 4096`

Leave the key location as default or specify path.

Enter a secure passphrase when prompted.

Transfer public key to server, replace “new user” with your username:

`ssh-copy-id newuser@server-ip-address`

Enter your login password when prompted.

Public key is now active! Disable password login by changing PasswordAuthentication to no via:

`sudo nano /etc/ssh/sshd_config`

Restart the ssh service:

  1. `sudo systemctl restart sshd`

SSH access is now restricted to your public key!

Optimizing Performance

To ensure Ubuntu Server runs smoothly on the Raspberry Pi hardware, some tuning steps can be followed:

Allocate RAM for Video Memory

By default RPi uses a portion of RAM for GPU. This isn’t required for server use.

  1. Edit /boot/firmware/nobtcmd.txt 
  2. Add at end: 
  1. gpu_mem=16 

This sets video memory to minimum 16MB, the rest is used as system RAM.

Overclock RPi4 CPU

Overclock at your own risk!

For stable, moderate gains edit /boot/firmware/usercfg.txt:




Save file after changes and reboot. Monitor CPU temperature under load.

Enable Caching for MicroSD Card

  1. Install raspi-config tool: 

    `apt install raspi-config`

  1. Run tool and select Performance Options > RAM caching for SD card 

This enables using spare RAM as block cache for SD card I/O performance gains.

Installing Docker

With Ubuntu Server optimized on the Raspberry Pi, you can now install software. Docker container platform allows bundling apps/services into standardized units for simplified deployment and management.

Follow Docker’s Ubuntu install guide:

sudo apt update

sudo apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo “deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update

sudo apt install docker-ce

With Docker now installed, containerized apps like webservers, databases, media servers etc. are quick to deploy.

Key Takeaways

  • The Raspberry Pi 4 handles Ubuntu Server smoothly allowing self-hosting useful services
  • Optimizing memory, CPU speed and caching helps for performance gains
  • SSH access should be restricted after initial setup
  • An uncomplicated firewall provides simple stealth port protection
  • Docker simplifies deploying containerized apps tailor-made for services/web apps
  • Overall an affordable, maker-friendly server platform


Installing Ubuntu Server on a Raspberry Pi is easy thanks to the 64-bit arm64 image supporting the RPi 4 hardware. Performance tuning and configuring security provides a robust environment for hosting web applications. The Pi’s low power usage, silent operation and reduced cost makes it perfect for always-on, environmentally friendly home and SMB hosting. With ample capabilities supporting containers via Docker, it serves as a compact learning platform for server technologies applicable to larger scale infrastructure.

Frequently Asked Questions

  1. Where can I find Ubuntu Server for the RPi?
    The official image for RPi 4 models is available on Ubuntu’s download page. Earlier RPi models may also work but have not been tested or optimized. 
  2. Can I connect peripherals like webcam or mic?
    Yes, additional USB accessories for audio, video, serial comms etc. are fully supported. 
  3. How do I connect wireless instead of ethernet?
    A USB WiFi dongle can be configured instead of ethernet. But wired connections are preferred for reliability. 
  4. My Pi heats up under load, what can be done?
    Use an aftermarket heat sink clipped to the SoC chip for cooling capabilities. Moderate overclocks may work but extensive load is not ideal. 
  5. My SD card feels slow, will an SSD work better?
    SSD storage can help with I/O intensive apps. Enabling RAM caching optimizes SD card speeds greatly too. 
  6. Can I use Cloud-Init or Multipass with Ubuntu Server on RPi?
    Unfortunately neither Cloud-Init or Multipass work currently with arm64 based systems except AMD64/x86 machines. 
  7. Does Ubuntu Server offer a desktop interface?
    No, Ubuntu Server is strictly CLI based. An alternative OS image should be used if desktop interface is required. 
  8. How frequently are security updates made available?
    Canonical provides security patches for a minimum of 5 years in all LTS releases, applied automatically or on user trigger. 
  9. Can I run older versions of Ubuntu Server on the Pi?
    64-bit support only extends from Ubuntu 20.04 onwards. Earlier releases will not work properly on RPi 4 hardware. 
  10. Is Docker the only way to run apps/services?
    Docker provides standardized containers but apps can still be installed directly. Virtual machines are not currently supported though. 
  11. How long will installation and setup take?
    Flashing the SD card takes under 5 minutes typically. Boot and filesystem expansion may need 1-2 reboots occupying under 15 minutes. Basic install and security steps should take well under an hour following this guide. 
  12. Can I backup or clone an existing RPi Ubuntu Server installation?
    Yes the SD card image can be directly copied to clone the setup. Key configuration files may need editing for network or account settings. 
  13. Does the OS installation stay intact if powered down?
    Yes, Ubuntu Server retains all changes permanently as long as the SD card is intact in the powered down state across reboots. 
  14. Can I run a web server on Ubuntu Server RPi?
    Yes, web servers like Apache and Nginx work perfectly to host websites and web apps on platforms like WordPress. 
  15. Will my peripherals continue working if I migrate from Raspbian to this?
    Custom hardware like sensors etc. should function the same via wiringPi if software libraries are recompiled or replaced by Ubuntu versions. 
  16. Does Ubuntu Server offer clustering for multi-node setups?
    Yes, clustering services allow synchronizing configurations and jobs across multiple RPC servers on the network. 
  17. How easy is restore from backup if OS gets corrupted?
    Simply flashing the backup image to a replacement SD card and changing unique IDs or configs will revive the original setup without hassles. 
  18. Does Ubuntu Server on ARM have any limitations compared to x86?
    No major limitations hamper ARM functionality today. Critical enterprise hardware compatibility needs checking before deploying though. 
  19. Which model Pi should I purchase for best performance?
    RPi 4 with 4GB or 8GB RAM is recommended for lag free performance under typical loads for home users. The 2GB option suffices for very basic workloads too. 
  20. Where can I find assistance for addressing issues faced?
    Check the Ubuntu forums and Stack Exchange sites for community support. Documentation guides handle most troubleshooting steps.

Leave a Comment