In this tutorial, we walk you through the process of installing Ubuntu Core on a Raspberry Pi, connecting it to the internet and using it remotely.
Bear in mind, Ubuntu Core is production-friendly, not necessarily developer-friendly. We recommend you use Ubuntu Core for “fire and forget” purposes where you won’t want to iterate on the software.
With Ubuntu Core, you are able to execute remote updates and patches for your appliances and devices, but for development and prototyping, we recommend Ubuntu Server. Let’s start!
What you’ll learn
- How to create a bootable Ubuntu Core microSD card
- How to setup internet connectivity on the Raspberry Pi
- 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
Following these steps will erase all existing content on the microSD card.
- Insert the microSD card into your computer
- Install the Raspberry Pi Imager tool for your operating system. You can do this with the following links:
- Save this file somewhere safe and install it on your computer.
- Run the imager and click “CHOOSE OS”
- Once this is done, start the Imager and open the “CHOOSE OS” menu.
- Scroll down the menu click “Ubuntu”.
- You will then be able to see a list of Ubuntu downloads to choose from. For this tutorial we recommend you select the Ubuntu Core 18 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.
- Select the image and open the “SD Card” menu. Select the microSD card you have inserted.
- Finally, click “WRITE” and wait for the magic to happen… (This magic might take a few minutes)
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 Ubuntu Core
Insert the flashed SD card into your Raspberry Pi. Attach your monitor and keyboard to the Pi and connect it to your power source. Then, follow the instructions on screen.
- Press enter to configure
- Press OK to configure the network and setup an admin account on this all-snap Ubuntu Core system
- 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.
- 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.
- 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.
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:
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.
Once you have inputted your email and the Pi has connected to you account it will give you an ssh command to connect to your pi. Run that command. It will be something like:
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!