How to install Ubuntu Core on your Raspberry Pi

Key Value
Summary A complete guide to installing the latest version of Ubuntu Core on your Raspberry Pi 4, 3 or 2.
Categories iot, raspberrypi
Difficulty 2
Author Canonical Web Team webteam@canonical.com

Overview

Duration: 2:00

In this tutorial, we will walk you through the process of installing Ubuntu Core on a Raspberry Pi, connecting it to the internet and using it remotely.

Keep in mind that Ubuntu Core is aimed at production deployments. We recommend you use Ubuntu Core on Raspberry Pi to test production-ready scenarios or for “fire and forget” purposes where you want a stable appliance-like experience.

With Ubuntu Core, you are able to execute remote updates and patches for your appliances and devices, but for easier development and prototyping, we recommend Ubuntu Server. Let’s start!

What you’ll learn

  1. How to create a bootable Ubuntu Core microSD card
  2. How to setup internet connectivity on the Raspberry Pi
  3. How to access your Raspberry Pi remotely

What you’ll need

  • A microSD card (4GB minimum, 8GB recommended)
  • A computer with a microSD card drive
  • A Raspberry Pi 2, 3 or 4
  • A micro-USB power cable (USB-C for the Pi 4)
  • A Wi-Fi network or an ethernet cable with an internet connection
  • A monitor with an HDMI interface
  • An HDMI cable for the Pi 2 & 3 and a micro HDMI cable for the Pi 4
  • A USB keyboard

Prepare the SD Card

Duration: 15:00

:warning: Warning
Following these steps will erase all existing content on the microSD card.

  1. Insert the microSD card into your computer
  2. Install the Raspberry Pi Imager tool for your operating system. You can do this with the following links:

Or, if you are on Ubuntu, you can run:

sudo snap install rpi-imager
  1. Once this is done, start the Imager and open the “CHOOSE OS” menu.

  1. Scroll down the menu click “Other general-purpose OS”.

  1. Here you can select Ubuntu and see a list of download options. For this tutorial we recommend you select the latest version of Ubuntu Core 32-bit armhf download. As indicated in the imager this will work for the Raspberry Pi 2,3, 3+ and any of the 4’s.

    If you intending to install an application that requires 64-bit compatibility, such as MicroK8s, make sure you alternatively select Ubuntu Core 20 64-bit IoT OS for arm64 architecture.

  1. Select the image and open the “SD Card” menu. Select the microSD card you have inserted.

  1. Finally, click “WRITE” and wait for the magic to happen… (This magic might take a few minutes depending on the SD card speed)

Create an Ubuntu SSO account

An Ubuntu SSO (Single Sign-On) account allows you to store SSH public keys and tie them to an email address. This allows your Ubuntu Core devices to authorize SSH connections only from devices with public keys matching the ones in your SSO account.

Obviously, if you already have an SSO account you can skip this step, you will have one if you used Ubuntu Core before, or if you have an account in the snapstore. If you do not, you need to go to the Ubuntu SSO login site, select that you don’t have an account and fill in your details. Once you have created your account come back to this tutorial and carry on.

Boot and configure Ubuntu Core

Duration: 7:00

Insert the flashed SD card into your Raspberry Pi. Attach your monitor and keyboard to the Pi and connect it to your power source.

From this point, it can take around five minutes for the system to instantiate itself. You will see typical Linux output on the screen, periods where there’s just a flashing cursor, and messages like Installing the system, please wait for a reboot. When this process has finished, you will see instructions on your screen.

  1. Press enter to configure
  2. Press OK to configure the network and setup an admin account on this all-snap Ubuntu Core system
  3. If you are using ethernet you simply need to connect your ethernet cable and select done. If you are wanting to use a local wifi network, use the arrow keys on your keyboard to navigate to wlan0 and hit enter. Here you will be able to configure your wifi settings.
  4. Select “Done” and the network config will progress.

Note: For this simple tutorial you will only need to input your network SSID and password. Once you have done that you won’t need to do any other network configuration. Using DHCP for IPv4 is fine.

  1. Next, you will need to enter the email address that is connected to your SSO account

Note: Don’t dawdle, for security reasons if you’re inactive for more than a minute the Pi will ask you to start over.

Once the setup is complete, the device will automatically update and if necessary restart. This could take another 10 minutes to complete.

Now, if you made an SSO account for the first time during this tutorial, you will not have any SSH keys. If you don’t have any SSH keys follow this next step. If you do, feel free to jump to the next section.

Generating an SSH key pair

For this, you need to open a terminal on your computer and run the following commands:

mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa

This will generate a 2048-bit RSA key pair, which is secure enough for most use cases (you may optionally pass in the -b 4096 flag to the ssh-keygen command, to create a larger 4096-bit key). You’ll see what this actually means in a few moments.

After entering the command, you should see the following output:

Press ENTER to save the key pair into the .ssh/ directory in your home directory or specify an alternate path.

If you had previously generated an SSH key pair, you may see the following prompt: “If you choose to overwrite the key on disk, you will not be able to authenticate using the previous key anymore.” Be very careful when selecting “yes”, as this is cannot be reversed and your existing key will be overwritten.

You should then see the following prompt:

Here, you enter a secure passphrase. A passphrase adds an additional layer of security to prevent unauthorized users from logging in.

You should then see something like the following output:

You now have a public and private key that you can use to authenticate. The next step is to place the public key on your Raspberry Pi so that you can use SSH-key-based authentication to log in.

So, now you will need to copy the contents of the file you just created to this site: https://login.ubuntu.com/ssh-keys

To do so you can run:

cat ~/.ssh/id_rsa.pub

In the terminal and copy the result into the text field on the website. Click import and if you have copied everything correctly you will have the key set up.

SSH in

Once you have inputted your email and the Pi has connected to your account it will give you an ssh command to connect to your pi. Run that command. It will be something like:

ssh rhys-davies@192.168.1.xxx

And your terminal should welcome you to Ubuntu Core.

That’s all folks!

You are done! Up and running on Ubuntu Core.

You also might want to install some software on your Pi. You can use the snap command to install snap packages. The Snap Store is where you can find the best Linux open source and proprietary apps to install on your Raspberry Pi and get started with any project!

Further reading

1 Like

Suggestion: Include instructions on how to install Ubuntu Core on an SSD drive now that the Pi4 supports stable SSD booting please. Thank you! :smiley:

1 Like

Is it possible to install Ubuntu Core 14.04 by just getting the ARM64 version for Raspberry Pi 4? Or are there specific things in these images that limit me from doing so?

Hi,

Take a look on this: https://medium.com/@zsmahi/make-ubuntu-server-20-04-boot-from-an-ssd-on-raspberry-pi-4-33f15c66acd4

Regards,

Luiz Almeida

Hi @rhys-davies,

Thank you for your tutorial.
I did something similar to your tutorial.
Instead of to install in the microSD card I installed in a external SSD drive.
Here you can find the steps.
My problem was after run "sudo apt upgrade" in the Ubuntu running from the external SSD drive.
The PI4 lost its boot info.
Do you know if the Ubuntu team intend to fix it as a lot of people intend to use Ubuntu on PI4 running from a external SSD drive?
Best regards,

Luiz Almeida

1 Like

Hi @luizmendesalmeida, the team certainly intend to fix this, thank you for your comment I’ll raise it with the right folks again now :slight_smile:

@rhys-davies Thanks for the tutorial. However, I have a few questions using 18.04 Core.

  1. I can ssh into the RPi from another linux machine, but when I do this from Windows using Putty, I have no idea what un and pw to use. I tried “ubuntu” but no luck. I tried my ubuntu website credentials but no luck.
  2. I am just learning Core and Snap. I understand that there is no need to “update,upgrade”? Is there a method to install the traditional Ubuntu 18.04 instead? I want to install an app that is compatible only with 18.04 and certain version dependencies.
1 Like

This generated link is not relevant for SSH command line:

(mailto:rhys-davies@192.168.1.xxx)
1 Like

You’re right of course, I have no idea where that came from, probably copy pasta, thanks for the heads up :sweat_smile:

Hi Jax, sorry for the delay here I didn’t seem to be notified.

  1. I’m unfamiliar with exactly what Putty requires unfortunately but I would suggest trying the password associated with your Windows machine in case it’s requiring access. Otherwise, unless you’ve changed it the password should be what you set when generating the keys on your Ubuntu One account.

  2. Correct, there is no need to run commands such as apt-get update and apt-get upgrade with snaps since they update automatically. You can install Ubuntu 18.04 by following this tutorial and selecting the 18.04 option in the imager:

However, might I ask what that app is? If it’s not a snap yet so that it doesn’t work on Ubuntu Core maybe I can help and make it so?

Ubuntu Core does not enable any password based logins by default but only allows ssh key based authentication (this is also the main reason that Ubuntu SSO accounts are needed, SSO is the central place to store the public key that Core downloads when you set it up)

you need to import the private part of the ssh key that you added to your Ubuntu SSO account into putty (there should be plenty of documentation online about setting up key based authentication in putty), then you should be able to connect without seeing a login prompt.

now … that said … if you can log in from a linux box, you can also simply set a password on the device (note this reduces security over using ssh keys) by running:

$ sudo passwd $USER

and then use the password you did set at the login prompt of the putty terminal.

fyi. I tried the custom nextcloud-core18-pi.img.xz as I wanted to test Collabora Online Development Edition on my Pi 400, I couldn’t change eth0 to wlan0. I have no ethernet cable so I had to end my test. The notes say to use a Pi 4, I assumed these are the same capability as the Pi 400, so could be my problem! Otherwise something isn’t working correctly.

i think the pi400 is only supported properly with UC20, the image you used is UC18 based … try simply using one from

after finishing the setup you can then just

snap install nextcloud

info about extra config you can do is at:

A post was split to a new topic: SSH Key in Windows

Its still need monitor and keyboard.

how we can provide predefined user name / sso.

example

touch /sdcard/boot/sso-user
echo “kokoye2007@gmail.com” > /sdcard/boot/sso-user

or other preset option ?

snap set <snapname> username=foo password=bar

meta/hooks/configure

#!/bin/sh

if ! username=$(snapctl get username); then
    echo "Username is required"
    exit 1
fi

if ! password=$(snapctl get password); then
    echo "Password is required"
    exit 1
fi

# Handle username and password, perhaps write to a credential file of some sort.
echo "user=$username" > $SNAP_DATA/credentials
echo "password=$password" >> $SNAP_DATA/credentials
chmod 600 $SNAP_DATA/credentials

see:

note though that Ubuntu core by design is not really made for having a user … while the reference developer images we provide give you an initial setup wizard to configure network and user, most actual devices running it (appliances, PLCs and industrial controllers, robots, manageable switches and APs, mediacenters, consumer electronics, POS systems, medical devices, webcams and digital signage) do use an agent snap to manage them via some fleet management software … while a user is actually required doing development or for home usage, it is considered a security hole on most of the above devices (at least by most of the companies that use it) …

here is also a demo snap that does it via hooks, similar to what you describe above, note though that this is rather a hack, circumventing the above rather secure assertion model:

1 Like

A post was split to a new topic: Unable to login to Ubuntu Core

This tutorial is linked from https://ubuntu.com/tutorials/getting-started-with-microk8s-on-ubuntu-core#1-introduction. This tutorial recommends selecting 32-bit armhf platform for Raspberry Pi but microk8s snap does not support that platform on ubuntu core.