Baby's First Raspberry Pi Ubuntu Server: 20.10

Getting Started

We'll be using the Raspberry Pi Imager to write the OS to our SD Card. At the time of writing this, I am using a Windows 10 Pro PC to image the SD Card and we'll be using the Ubuntu Server 20.10 x64 image.

Download the Raspberry Pi Imager and install the .exe.  From there we'll insert the SD Card into our system and open up the  Raspberry Pi Imager.  Once open we'll click on the "CHOOSE OS" button, select "Other general purpose OS" > Ubuntu > Ubuntu Server 20.10 64-bit.  Next you'll click on "CHOOSE SD CARD" and select the SD Card that we're going to be using for the OS; click "WRITE" and read the warning that pops up.  If you agree to the warning, click yes and wait for the process to finish.

** Please note that if there is anything written to your SD Card, the image flash will delete all of its contents.

First Boot

Now that the image has been successfully written to the SD Card, you may pull it out of your PC and insert the card into your Raspberry Pi.  Turn on the Raspberry Pi while connected to your monitor and keyboard.  Once booted up, you'll notice that unlike a regular Ubuntu Server install, there is no setup screen.  You will be taken directly to the login prompt.  The default username and password is "ubuntu" minus the quotation marks.

Now we'll sign in using the default credentials noted above.

Setting a Static IP

By default your gigabit ethernet port will be set to DHCP and will receive a DHCP lease from your DHCP server (may be a stand-alone DHCP server or off of your ISP provided router).  As this is a server that will be used to host different services, I like to set the IP address statically to prevent any hassle in the future if the DHCP provided IP is lost.

**You may skip to the next section if you plan on keeping the interface set to DHCP.**

To do this we'll start by locating the netplan config which is found in the /etc/netplan/ directory.  To locate the name of the file, we'll use the ls command as seen below:

ubuntu@ubuntu:~$ ls /etc/netplan/
50-cloud-init.yaml

From the output we see the file 50-cloud-init.yaml, this is the file we'll be editing next.  To edit the file we'll use nano, a text editor, which already comes installed with our Ubuntu Server image.  You should see something similar to the below.

ubuntu@ubuntu:~$ sudo nano /etc/netplan/50-cloud-init.yaml

network:
    ethernets:
        eth0:
            dhcp4: true
            match:
                driver: bcmgenet smsc95xx lan78xx
            optional: true
            set-name: eth0
    version: 2

In my case, I will be assigning this device the IP of 10.0.100.242/24 with a gateway of 10.0.100.1.  The gateway will also act as the DNS server.  So we'll need to change the config up above to match the one below:

network:
    ethernets:
        eth0:
            addresses: [10.0.100.242/24]
            gateway4: 10.0.100.1
            nameservers:
                addresses: [10.0.100.1]
            match:
                driver: bcmgenet smsc95xx lan78xx
            optional: true
            set-name: eth0
    version: 2

**Make sure to select an IP address and gateway that works with your environment.

Now we will apply the config:

ubuntu@ubuntu:~$ sudo netplan apply

Then we'll check the interface to ensure it's using our config:

ubuntu@ubuntu:~$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether REDACTEDLUL brd REDACTEDLUL
    inet 10.0.100.242/24 brd 10.0.100.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 REDACTEDLUL scope link
       valid_lft forever preferred_lft forever

Finally, we'll ping Google DNS in order to confirm we can leave our internal network:

ubuntu@ubuntu:~$ ping 8.8.8.8 -c 4
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=24.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=23.8 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=24.4 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=118 time=25.3 ms

--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 23.770/24.437/25.302/0.552 ms

If all goes well, you'll see four packets transmitted and 4 received!

Updating Your Raspberry Pi

Now that we've confirmed we have internet access, we'll want to update our Ubuntu Server install, this will include package and security updates.

First we'll update the list of packages:

ubuntu@ubuntu:~$ sudo apt update
~
Fetched 1194 kB in 2s (541 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
49 packages can be upgraded. Run 'apt list --upgradable' to see them.
ubuntu@ubuntu:~$

As seen above, there are 49 packages that can be upgraded.  To upgrade all of the packages at once, we'll use apt full-upgrade with the -y flag which will auto accept all Yes/No requests.

ubuntu@ubuntu:~$ sudo apt full-upgrade -y

Once this is complete we'll adjust the time zone of the device:

ubuntu@ubuntu:~$ sudo dpkg-reconfigure tzdata

You'll be greeted by the screen below, go through the prompts using your arrow keys and select your time zone.

If successful, you should see the following with correct local time:

ubuntu@ubuntu:~$ sudo dpkg-reconfigure tzdata

Current default time zone: 'US/Eastern'
Local time is now:      Sat Jan  2 06:39:22 EST 2021.
Universal Time is now:  Sat Jan  2 11:39:22 UTC 2021.

ubuntu@ubuntu:~$

Yes, I was writing this at 6AM =).

Changing the Username and Hostname on the Raspberry Pi

As I'm sure you've noticed, we're still using the default username and hostname on our Raspberry Pi.  Lets change that!

As we're already logged in with our ubuntu user, we'll set a password for root using the below and follow the prompts:

ubuntu@ubuntu:~$ sudo passwd root

Once the root password is set, you'll want to exit the ubuntu user session

ubuntu@ubuntu:~$ exit

Sign in as root and run commands below.

First we'll edit the ubuntu username:

ubuntu@ubuntu:~$ usermod -l <new username> -d /home/<new username> -m <old username>

Example:
ubuntu@ubuntu:~$ usermod -l Spooky -d /home/Spooky -m ubuntu

Next we'll edit the user's group:

ubuntu@ubuntu:~$ groupmod -n <new group name> <old group name>

Example:
ubuntu@ubuntu:~$ groupmod -n SpookyGroup ubuntu

Lastly, we'll lock the root account to prevent login:

ubuntu@ubuntu:~$ passwd -l root

Now we'll exit the root session and log in with our new username.

Finally we'll edit the hostname file with the hostname of the your choice!

Spooky@ubuntu:~$ sudo nano /etc/hostname

You'll see that the file only contains the ubuntu hostname, change it to what you'd like and save.  Then we'll restart the Pi for the change to take effect.

Spooky@ubuntu:~$ sudo reboot

And we're done!

Conclusion

To sum this up, we've used the Raspberry Pi Imager to image the Ubuntu Server 20.10 OS onto our SD Card.  We then set a static IP, updated the installed packages, changed the time zone to our own, updated the username/group name and hostname on our Raspberry Pi.

You should now have a good base to start messing around with your Raspberry Pi.  I believe the next step to go through after this will be to create SSH keys for more secure access.

That tutorial from me will have to wait until I'm not lazy. =)


**<WIP>**
This is a WIP as I'm lazy.  More info and screenshots soon =)!  Maybe a comments section once I figure out how to do it.