09/15/2025
Linux Ubuntu Server Guide
Admin Tasks
This post is continuously updated to include tutorials on basic admin tasks for the linux and mac operating systems.
1. Installing Linux on Raspberry Pi
2.
Installing Linux on Raspberry Pi
If you are installing Ubuntu linux, go to https://cdimage.ubuntu.com/releases/ and select the version you want to install. For embedded devices, select the preinstalled version and the 64-bit ARM architecture. This is a plug and boot image. Note that the install image (not preinstalled) will not boot properly on the raspberry pi.
Burn the preinstalled image to an SD card with a minimum of 32GB of storage, and plug it into your raspberry pi. Power on the raspberry pi and linux should boot up.
The default login credentials are:
user: ubuntu
password: ubuntu
Basic System Update (linux)
It's recommended to update packages when booting for the first time to ensure the database has a list of the latest package sources
sudo apt update (update package sources)
sudo apt upgrade -y (poll package sources for package updates)
You might encounter an error:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3776 (unattended-upgr)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
This is a typical automatic update background process (pid=3776 in my case) that can be killed using:
sudo kill -9 3776
Now run the upgrade command again.
Setting Up Wifi (linux)
Each linux distro uses a different package for managing Internet connections. For the common Ubuntu distro, netplan is used.
Find your wifi network interface name using "ip a" or "ls /sys/class/net". It's usually wlan0. Edit the netplan config file at "/etc/netplan/50-cloud-init.yaml" and add in:
network:
wifis:
wlan0:
access-points:
"ssid":
password: "wifi_password"
dhcp4: true
This configs the raspberry pi to connect to wifi, but your internal ip will change occasionally because dhcp is set to true. You won't be able to connect to the Internet either because you haven't specified a gateway ip, but other devices in your network will be able to access this device.
This is the config I use for static internal ip, and Internet connection:
network:
wifis:
wlan0:
access-points:
"ssid":
password: "wifi_password"
dhcp4: false
addresses:
- 192.168.x.x/24
gateway4: 192.168.x.x
nameservers: [8.8.8.8, 1.1.1.1]
The "addresses" field specifies the desired internal ip, "gateway4" is the ip of your router. "nameservers" are optional but I like to include the google DNS servers. Apply these settings using:
sudo netplan apply
You will be connected to your network in a couple of seconds. Check you have the desired ip using "ip a", and try pinging google.ca using "ping google.ca".
Partitioning disks (mac)
1. diskutil list
2. diskutil unmountDisk /dev/disk2
3. sudo diskutil eraseDisk FAT32 SDCARD MBRFormat /dev/disk2
Managing Processes (linux)
The "ps" command is used to view all processes. Common arguments are "aux", where "a" shws all user processes, "u" displays the process owner, and "x" shows processes not attached to terminal sessions like background daemons. You can also pipe the output to "grep" to filter out processes based on keywords.
ps aux | grep
Omit "a" argument to only see your own processes.
Commands you enter into the terminal always run in the foreground first. You can move a foreground process to the background using:
Ctrl+Z (suspend process in background)
bg (continue to run process in background)
Alternatively, you can add a "&" to the end of the command to start process in background. For example:
python3 script.py &
The "jobs" command lists all background processes. Use it to see the job number of a process. You can bring a background process to the foreground and stop it using:
fg %# (brings job # to foreground)
Ctrl+C (stop process)
If you want to continue running the processes even when the terminal closes, use:
nohup python3 script.py &
Updating Permissions (linux)
"chmod" is used to specify the read, write, execute permissions of a file or directory.
chmod
Permissions can be specified using three binary numbers where:
7 111 (read, write, execute)
5 101 (read, execute)
0 000 (no permissions)
"chown" is used to change the file owner. You can change ownership using:
sudo chown (change just user owner)
sudo chown : (change user and group owner)
sudo chown -R : (change user and group owner recursively)
Note that you will get an error if a group doesn't exist.
sudo chown :
chmod +x
sudo chmod 640
sudo adduser
Inspecting Logs (linux)
The "journalctl" command is used to see all logs coming from all services on linux.
sudo journalctl (see logs from top)
sudo journalctl -r (see logs from bottom/latest)
sudo journalctl -u -b (see logs from top)
sudo journalctl -n (see latest logs)
sudo journalctl -f (follow live log updates)
Setting Up GUI (linux)
To install a minimal desktop environment:
sudo apt install gnome-session gdm3 gnome-terminal (gnome)
sudo apt install xfce4 xfce4-goodies lightdm (xfce)
On the Ubuntu distro, you can use the following shortcut:
sudo apt install ubuntu-desktop (gnome for ubuntu distro)
sudo apt install xubuntu-desktop (xfce for ubuntu distro)
A display manager loads the desktop environment. During setup, you will be asked to select a display manager. Select gdm for gnome and lightdm for xfce to avoid display issues.
If you installed more than one display manager, you can switch between them using:
sudo dpkg-reconfigure
Remember to reboot to apply the changes.
The desktop environment can be booted on startup or immediately started by starting the display manager service on linux.
sudo systemctl start (start gui)
sudo systemctl stop (stop gui)
sudo systemctl restart (restart gui)
sudo systemctl set-default graphical.target (set gui to load on boot)
sudo systemctl set-default multi-user.target (use no gui on boot)
startx (start gdm)
startxfce4 (start xfce)
The config file for gdm and lightdm are saved at "/etc/gdm3/custom.conf" and "/etc/lightdm/lightdm.conf" respectively. This file needs to be created by you.
To display Wayland support, which may cause display issues if you're using gnome, add this line into the gdm config file and restart the service:
WaylandEnable=false
If you want to remove a desktop environment, use "apt purge" on all the packages mentioned during installation.
sudo apt purge
sudo apt autoremove --purge
Configuring Firewall
sudo ufw status [verbose] (get firewall status)
sudo ufw allow (allow external access to port using tcp or udp)
sudo ufw reload (apply changes)
Setting Up SSH Server
A remote user will save ssh keys of your server to catch man-in-the-middle attacks. If you have a new server with the same internal ip address as the old one, remote users will not be able to login. Delete the old ssh key and reconnect to save the new key.
ssh-keygen -R
ssh user@
Alternatively, you can edit the list of ssh known keys file: ~/.ssh/known_hosts
Setting Up FTP Server
sudo apt install vsftpd
sudo systemctl enable vsftpd
Below are some common FTP commands:
ftp
user
status (get ftp settings and mode)
prompt (toggle interactive mode)
Turn off interactive off using prompt to turn off confirmation when writing to server
! (run shell command)
pwd (get current directory on server)
cd (change directory on server)
lcd (change directory on local machine)
get (download file from server)
mget (download multiple files from server
put (upload file to server)
mput (upload multiple files to server)
mput * (upload all files in current directory)
delete (delete file on server)
mdelete (delete multiple files on server)
mdelete * (delete all files in current directory)
rename (rename file on server)
ascii (ascii mode for text files)
binary (binary mode for images, zips)
magick input.pdf output.jpg
magick -density 300 input.pdf -quality 100 output.jpg (convert pdf pages to jpg for printing)
Admin Tasks
This post is continuously updated to include tutorials on basic admin tasks for the linux and mac operating systems.1. Installing Linux on Raspberry Pi 2.Installing Linux on Raspberry Pi If you are installing Ubuntu linux, go to https://cdimage.ubuntu.com/releases/ and select the version you want to install. For embedded devices, select the preinstalled version and the 64-bit ARM architecture. This is a plug and boot image. Note that the install image (not preinstalled) will not boot properly on the raspberry pi. Burn the preinstalled image to an SD card with a minimum of 32GB of storage, and plug it into your raspberry pi. Power on the raspberry pi and linux should boot up. The default login credentials are: user: ubuntu password: ubuntu Basic System Update (linux) It's recommended to update packages when booting for the first time to ensure the database has a list of the latest package sources
sudo apt update (update package sources) sudo apt upgrade -y (poll package sources for package updates)You might encounter an error:
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 3776 (unattended-upgr) N: Be aware that removing the lock file is not a solution and may break your system. E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?This is a typical automatic update background process (pid=3776 in my case) that can be killed using:
sudo kill -9 3776Now run the upgrade command again. Setting Up Wifi (linux) Each linux distro uses a different package for managing Internet connections. For the common Ubuntu distro, netplan is used. Find your wifi network interface name using "ip a" or "ls /sys/class/net". It's usually wlan0. Edit the netplan config file at "/etc/netplan/50-cloud-init.yaml" and add in:
network: wifis: wlan0: access-points: "ssid": password: "wifi_password" dhcp4: trueThis configs the raspberry pi to connect to wifi, but your internal ip will change occasionally because dhcp is set to true. You won't be able to connect to the Internet either because you haven't specified a gateway ip, but other devices in your network will be able to access this device. This is the config I use for static internal ip, and Internet connection:
network: wifis: wlan0: access-points: "ssid": password: "wifi_password" dhcp4: false addresses: - 192.168.x.x/24 gateway4: 192.168.x.x nameservers: [8.8.8.8, 1.1.1.1]The "addresses" field specifies the desired internal ip, "gateway4" is the ip of your router. "nameservers" are optional but I like to include the google DNS servers. Apply these settings using:
sudo netplan applyYou will be connected to your network in a couple of seconds. Check you have the desired ip using "ip a", and try pinging google.ca using "ping google.ca". Partitioning disks (mac) 1. diskutil list 2. diskutil unmountDisk /dev/disk2 3. sudo diskutil eraseDisk FAT32 SDCARD MBRFormat /dev/disk2 Managing Processes (linux) The "ps" command is used to view all processes. Common arguments are "aux", where "a" shws all user processes, "u" displays the process owner, and "x" shows processes not attached to terminal sessions like background daemons. You can also pipe the output to "grep" to filter out processes based on keywords.
ps aux | grepOmit "a" argument to only see your own processes. Commands you enter into the terminal always run in the foreground first. You can move a foreground process to the background using:
Ctrl+Z (suspend process in background) bg (continue to run process in background)Alternatively, you can add a "&" to the end of the command to start process in background. For example:
python3 script.py &The "jobs" command lists all background processes. Use it to see the job number of a process. You can bring a background process to the foreground and stop it using:
fg %# (brings job # to foreground) Ctrl+C (stop process)If you want to continue running the processes even when the terminal closes, use:
nohup python3 script.py &Updating Permissions (linux) "chmod" is used to specify the read, write, execute permissions of a file or directory.
chmodPermissions can be specified using three binary numbers where:
7 111 (read, write, execute) 5 101 (read, execute) 0 000 (no permissions)"chown" is used to change the file owner. You can change ownership using:
sudo chownNote that you will get an error if a group doesn't exist. sudo chown(change just user owner) sudo chown : (change user and group owner) sudo chown -R : (change user and group owner recursively)
sudo journalctl (see logs from top) sudo journalctl -r (see logs from bottom/latest) sudo journalctl -uSetting Up GUI (linux) To install a minimal desktop environment:-b (see logs from top) sudo journalctl -n (see latest logs) sudo journalctl -f (follow live log updates)
sudo apt install gnome-session gdm3 gnome-terminal (gnome) sudo apt install xfce4 xfce4-goodies lightdm (xfce)On the Ubuntu distro, you can use the following shortcut:
sudo apt install ubuntu-desktop (gnome for ubuntu distro) sudo apt install xubuntu-desktop (xfce for ubuntu distro)A display manager loads the desktop environment. During setup, you will be asked to select a display manager. Select gdm for gnome and lightdm for xfce to avoid display issues. If you installed more than one display manager, you can switch between them using:
sudo dpkg-reconfigureRemember to reboot to apply the changes. The desktop environment can be booted on startup or immediately started by starting the display manager service on linux.
sudo systemctl startThe config file for gdm and lightdm are saved at "/etc/gdm3/custom.conf" and "/etc/lightdm/lightdm.conf" respectively. This file needs to be created by you. To display Wayland support, which may cause display issues if you're using gnome, add this line into the gdm config file and restart the service:(start gui) sudo systemctl stop (stop gui) sudo systemctl restart (restart gui) sudo systemctl set-default graphical.target (set gui to load on boot) sudo systemctl set-default multi-user.target (use no gui on boot) startx (start gdm) startxfce4 (start xfce)
WaylandEnable=falseIf you want to remove a desktop environment, use "apt purge" on all the packages mentioned during installation.
sudo apt purgeConfiguring Firewall sudo ufw status [verbose] (get firewall status) sudo ufw allowsudo apt autoremove --purge
ssh-keygen -RAlternatively, you can edit the list of ssh known keys file: ~/.ssh/known_hosts Setting Up FTP Serverssh user@
sudo apt install vsftpd sudo systemctl enable vsftpdBelow are some common FTP commands: ftp