Ubuntu Server

Table of Contents

 


About

Ubuntu Server is commonly used to run all types of services including - databases,  websites, monitoring systems, and games. In most cases you will run this OS without a graphic interface, and interact with it using terminal commands.

Get it here: https://ubuntu.com/download/server

 

Installation Notes

  • Some versions of Ubuntu server only use half of the total disk space by default. Be sure to review the default Logical Volume and partition sizes - and configure them as you want.
  • You may be asked if you would like to pre-install packages for services like Docker, PostgresSQL, Nginx, etc. I would suggest avoiding these versions and following the developer's latest official install directions.

 

First Things

 

Tab is your friend

While using the terminal you can autocomplete commands and filenames by pressing the Tab button. This will save you time in typing and also help prevent typing errors.

Creating a non-root user

It is best practice to create a user account and give it permissions instead of using the root account. In most cases Ubuntu server will ask you to configure this user when you install, however this may not be the case if you are using a Linux container on a virtual machine host.

You can tell if you are using root based on your terminal screen. Aside from the leading name, root will have a trailing hash/pound symbol "#" and user accounts have a money symbol "$".

root@system_name:~# █
user_name@system_name:~$ █
  • Normal users are prompted for their password before making system changes whereas the root user has less password prompting.
  • Commands by user accounts are logged.
  • As a normal user you will need to place "sudo" before commands that make system changes, this stands for "substitute user do".

 

Add a new user

adduser new_user_name_here

Put user in the sudo group
This give the user permissions to make system changes

usermod -aG sudo username

List all users

awk -F: '$3 >= 1000 && $3 < 65534 { print $1 }' /etc/passwd

Delete a user

userdel username

Switch to another user

su - username

Update & Upgrade

The following command will reach out to the package repositories ["repos"] that are currently configured on your system and get a list of the latest available software for your system.

sudo apt update

When you want to upgrade your existing software packages you can run this command.

sudo apt upgrade

In most cases you will want to update, then upgrade.

 


 

Administration

 

File Management

 

Basics

List files in the current directory

ls

List files and show more information

ls -lh

Change directories

cd directory_name

Move 'up' one directory

cd ..

Return to your user 'home' directory

cd

Make a new directory

mkdir new_directory_name

Copy a file

cp existing_filename new_filename

Remove a file

Warning: be careful when removing files.

rm filename

 

Review disk space and directory sizes

The disk free command [df] will show the used, free, and total storage numbers for all our mounted filesystems. In this example the optional -h will make the output easier to read by putting the totals in larger units.

df -h

 

The disk usage command [du] will show the total data usage of each directory. By default it will list all directories within your current terminal location.You can specify a location at the end of the command. In this example the optional -h shows the data in a more readable format, the --max-depth=2 limits the subdirectories that are displayed, and the /home at the end is where a location other than the current terminal location can be specified.

du -h --max-depth=2 /home

 

The NCurses Disk Usage application is terminal based application that can help you review storage use.

sudo apt install ncdu

ncdu

 

Updating the OS

To check for an update you can run this command.

sudo do-release-update

There are may be several prompts throughout the process until you are asked to restart.

 

Managing software packages

 

Listing user-installed packages

Sometimes you may need to confirm which package you installed. This command will let you scroll through them as a list.

Press space to go to the next page of entries and press q to exit the list.

apt-mark showmanual | less

 

Accessing the server remotely

Once you have your server up and running you may prefer to manage it remotely, through another machine.

SSH Terminal for commands

You can access the server terminal using the ssh command from another machine.

If your username on the server is 'serv-admin' and your server is at IP address of 192.168.0.24 then you would type: ssh [email protected]

ssh username@server_ip_or_hostname

Type exit to end the remote session.

exit

 

File Transfer via SFTP

If you would like to easily pass files back and forth between a machine and a server with a graphic interface you can use an SFTP application on your machine. I prefer FileZilla for this.

 

Using the Screen Application

Screen is an application that allows you to run multiple terminal sessions [screens] in the basic terminal. This can be useful when you are running without a GUI operating system, like a server, and you have an application would normally 'take over' the entire terminal interface - essentially giving you the ability to multitask applications.

Install screen

apt install screen

Start a new named screen session

screen -S new_session_name

Leave a screen session without stopping it

Press Ctrl + a then d

Reconnect to a screen session

screen -r session_name

List existing sessions

screen -ls

Terminate a screen session from within the session

exit

Terminate a screen session from outside the session

screen -XS session_name exit

 


 

Other

 

Setting the timezone

This can be important for running services that rely on time sorting and tracking. 

View your time and settings.

timedatectl

Change your timezone with this command, replacing "America/Toronto" with your region.

sudo timedatectl set-timezone America/Toronto

List timezone regions with this command.

timedatectl list-timezones

 

Docker

Follow Docker's official install documentation here: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

 

.NET