Configure UFW Firewall on Ubuntu

Show status

sudo ufw status

Disable UFW Service

sudo systemctl stop ufw && sudo systemctl disable ufw

Stop UFW Service

sudo systemctl stop ufw

Start UFW service

sudo systemctl stop ufw

Enable UFW

sudo ufw enable

Allow SSH

sudo ufw allow 22/tcp

Show status

sudo ufw status numbered

Example output

sudo ufw status numbered
Status: active
To            Action   From 
--            ------   ----
[1] 3478/udp  ALLOW IN  Anywhere
[2] 5514/udp  ALLOW IN  Anywhere
[3] 8080/tcp  ALLOW IN  Anywhere
[4] 8443/tcp  ALLOW IN  Anywhere
[5] 8880/tcp  ALLOW IN  Anywhere
[6] 8843/tcp  ALLOW IN  Anywhere
[7] 6789/tcp  ALLOW IN  Anywhere
[8] 27117/tcp ALLOW IN  Anywhere
[9] 22/tcp    ALLOW IN  Anywhere

Delete rule

You need to know the number of the rule you want to delete. Replace number with the number of the rule from the status command

sudo ufw delete number

Reset rules

sudo ufw reset

Ubuntu expand disk space – Command Line

Warning: Be extremely careful when making changes to partitions and disk as it can lead to broken systems and lost data. Make sure you have a backup.

This scenario is done on a basic Ubuntu install. No fancy LVM stuff going on. If you need that, refer to here

Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2062ec28
Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 65011711 65009664   31G 83 Linux
/dev/sda2       65013758 67106815  2093058 1022M  5 Extended
/dev/sda5       65013760 67106815  2093056 1022M 82 Linux swap / Solaris

From the above output of fdisk -l, we see that the disk has 64GiB available, but the primary partition is only 31G. To make the primary partition larger we need to

  • Run fdisk “fdisk /dev/sda”
  • Delete partitions 2 and 5,
  • Delete Partition 1
  • Create Partition 1 again on the same starting boundary
  • Put the end boundary close to the end so we end up with ~62GiB for that partition
  • Recreate sda2, the 1GiB extended partition
  • Write changes to disk
  • Run resize2fs to resize the filesystem

You may need to boot up in recovery to get this command working. Also if you boot up in recovery, you’ll need to remount the root / partition read/write. More info here.

resize2fs /dev/sda1

Helpful Links

I deleted apt on Ubuntu, now what?

Apparently if you do

apt purge ubuntu*

You’ll end up deleting apt. Which is a bummer, because you can’t install anything else, or fix the problem. But not to worry, the resolution is fairly easy.

You can go download the apt deb from Ubuntu’s website and install it with dpkg.

Go to the following link and find the packages for your Ubuntu version

You’ll need to show “All packages” at the bottom of the page.

Download and install ubuntu-keyring, apt-transport-https, and apt packages. Example below


Install Packages

sudo dpkg -i ubuntu-keyring_2012.05.19_all.deb
sudo dpkg -i apt-transport-https_1.2.29ubuntu0.1_amd64.deb
sudo dpkg -i apt_1.6.6ubuntu0.1_amd64.deb

Run apt and make sure it is all working

sudo apt update && sudo apt upgrade

Install NextCloud on Ubuntu 19.04

Install with snap

sudo snap install nextcloud 

Set user and password for NextCloud

sudo nextcloud.manual-install nextcloudadmin password

Allow https access for firewall

sudo ufw allow 80,443/tcp

For the following steps to work, you’ll need an A record setup on your domain name server to point a domain to your Next Cloud servers public ip address. Change in the following steps to the domain name you’ve setup.

View trusted domains

sudo nextcloud.occ config:system:get trusted_domains

Setup new trusted domain. Change with your domain.

sudo nextcloud.occ config:system:set trusted_domains 1

Run through Lets Encrypt to setup a SSL certificate.

sudo nextcloud.enable-https lets-encrypt

Should be able to access NextCloud from a web browser

Extra info

Set static ip address in Ubuntu 19.04

The network configuration settings for the server edition of Ubuntu are now stored in the following location. Create the file if it does not exist.

sudo vi /etc/netplan/01-network-manager-all.yaml

Add or edit the config file to the following. Change eno1 to your interface name and the address and gateway to the appropriate IP’s

For more information, see netplan(5).
   version: 2
   renderer: networkd
      dhcp4: no
      addresses: []
        addresses: [,]

Now apply the changes with the following command.

sudo netplan apply

Verify Ubuntu iso on Windows

On Windows you can use the CertUtil utility to verify an iso image.

First, you’ll need the checksum of the iso. Should be on the page where you downloaded the iso. More info about that here.

Next generate the hash by running the following in a command prompt. Replace the path and ISO name with the one you downloaded

certutil -hashfile Downloads\ubuntu-19.04-live-server-amd64.iso sha256

Example output

SHA256 hash of Downloads\ubuntu-19.04-live-server-amd64.iso:
CertUtil: -hashfile command completed successfully.

Compare the output with the checksum. If they are the same, you should be good to go.