PersonalBlog

BASH Breadcrumbs

Some terminal commands that I’ve had to look up. I figure if I looked it up once, I might need it again. Thus do I begin this collection of BASH Breadcumbs


To explicitly create a standard, non-admin, account from primitives:

  • useradd -ms /bin/bash
  • passwd <username>

To explicitly create a standard admin, but non-root, account from primitives.
As superuser:

  • useradd -ms /bin/bash <username>
  • passwd <username>
  • usermod -aG sudo <username>

If no homedir (/home/<username>) directory is present then, as superuser:

  • mkhomedir_helper <username>

To set BASH as shell, as superuser:

  • sudo chsh -s /bin/bash <username>


To install Docker on Ubuntu 20.04

First, pick up the pre-reqs from the standard repositories.

  • sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Next add the Docker.com keys in order to use the official repository. This provides the recommended security level by getting the most up-to-date versioning as soon as it is available from the vendor instead of the distribution’s repository.

  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Notice the hyphen (-) at the end of the previous command. It is an important part of the syntax of the line.

Now that we have the keys, lets open that Docker.com repository.

  • sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

At this point it is a simple matter of running an update/upgrade cycle and installing the docker components.

  • sudo apt update && sudo apt upgrade
  • sudo apt install docker-ce docker-ce-cli containerd.io

Docker is now installed. Check with:

  • sudo docker ps

Add user to ‘docker’ group

In order to utilize docker without requiring admin privileges the user must be added to the ‘docker’ group.

  • sudo usermod -aG docker <username>

Now either log out and back in or change to <username> via the switch user (su) command.

  • su <username>


Installing Nextcloud onto Ubuntu 20.04 via Snap package.

Ok, this is not the best way to get a service like Nextcloud up and running. But it is absolutely the fastest and simplest.

  • sudo snap install nextcloud

St this point Nextcloud is running, but we need to open up the service to the outside world. By default it responds only to requests made on localhost. So we need to add some entries to the ‘allow-list’ like the fully-qualified-domain-name, and possibly the ip-address.

  • sudo nextcloud.manual-install <username> <password>

At this point nextcloud is running, but before we can use it we need to allow domains other than localhost to connect. You can check the current trusted domain list with the following:

  • sudo nextcloud.occ config:system:get trusted_domains

Use nextcloud.cc to add another trusted domain to respond to:

  • sudo nextcloud.occ config:system:set trusted_domains 1 –value=<you.domain.com>

Nextcloud is now working. You can log into it from your browser via the domain name with the account information you set up earlier. Except that you have zero security in communication with the server. One of the reasons you are likely setting up nextcloud is for the security and encryption options. So lets set up our SSL cert with Lets-Encrypt.

It is possibly you might be doing this with another SSL certificate option. But I will not go into how it might be used. I am assuming if you have your own cert you know how to utilized it.

Open up your default firewall. On Ubuntu this would be UFW. Using the following:

sudo ufw allow 80,443/tcp

And finally run the script built-in to the nextcloud snap with:

sudo nextcloud.enable-https lets-encrypt

Answer the questions and you are all ready! Enjoy your new nextcloud server.



Changing the default data volumes for the nextcloud snap

By default snaps don’t have access to anything outside of their own sandbox. Much like any other container type. So a companion module is needed to connect to nextcloud and provide this ability specifically.

  • sudo snap connect nextcloud:removable-media

This allows nextcloud to access /media for persistent data. The config file “/var/snapnextcloud/current/nextcloud/config/config.php” needs to be edited to make sure datadirectory points to a valid location inside of /media. Like “/media/nextcloud/data” for instance.

Before editing the config file though, shut down the nextcloud service. Otherwise unwanted consequences may ensue.

I use digital ocean for my VPS needs so far. I have a one VPS for my website, and a second for my nextcloud insance that will also run some docker stuff eventually. I also have a small 10 gig block volume to use as persistent cloud storage. The way I did this was to mount it to /media/vol1 inside my VPS file structure. This means my entry in config.php points to /media/vol1/data. I added lines to the /etc/fstab to mount this at boot time so this volume is always available under /media.

The procedure would look like this for me.

  • sudo snap disable nextcloud
  • sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
  • sudo mv /var/snap/nextcloud/common/nextcloud/data /media/vol1/data
  • sudo snap enable nextcloud

This just moves the files and storage to persistence. The database files, apps, and everything else remain inside the snap-sandbox.

Leave a Reply