Server Setup And Install

Table of Contents

This is specific to ubuntu (well ubuntu server) because currently it is the only linux distro I use for servers, these notes assume you know how to get and flash a ubuntu server iso image to a usb stick and follow the installation/setup menu.

if you get any errors google is your friend or dare I say it openAi’s chatGPT, I will add common errors and solutions if I come across any or if you do let me know.

I recommend just doing sudo su now so you don’t get any sudo errors doing things.

First Things

always update it! and we are going to install some things you will probably need.

sudo apt update && sudo apt upgrade -y

now I would give it a restart with

reboot

Note: this server is still being setup so it’s ok to reboot it all the time but when it’s “in production” (setup and being used) it is normally best practice (in my opinion) to only restart the service the docs for what your doing should says it uses.

then install the things

sudo apt install zip unzip curl git

Increase Storage To Use Full Disk

For some reason when you select use whole disk in the setup process the usable storage space is never the whole disk it’s sort of half I think never really checked, any way to have it use the whole available space there are a few commands to run.

first see if it for some magic reason actually used the whole disk you can use one of the following commands to see the size.

df -H
lsblk
vgdisplay

now to increase the storage space if you need to

lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

then

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

now use one of the commands to see if your disk what your looking for is ubuntu--vg-ubuntu--lv has increased if not troubleshoot time!

if it has yay! now I would give it a restart with

reboot

Install And Setup Fail2ban

soo this is as basic as it gets I normally don’t do this unless for example its a vps with no external firewall all i really use it for is to prevent people some how getting ssh access.

sudo apt install fail2ban

make sure its running

sudo systemctl status fail2ban

Auto Pull ssh keys from GitHub

For example it’s such a pain need to ssh in on your phone when you’re out but your phone’s key hasn’t been added yet sooo OOF. This this is just a simple script with a cron to pull your public ssh keys from GitHub.

First make sure you are the user you want to add ssh keys for so doing exit if you are root now cd to your .ssh folder and run the following commands:

cd ~/.ssh/
curl https://raw.githubusercontent.com/404invalid-user/server-scripts/main/ssh-key-sync.sh

now edit your username in the file by finding my GitHub username and replace it with yours.

nano ./ssh-key-sync.sh

now set up the cron, I say every 15-30 minutes is the best pick lower if you are constantly updating your keys and higher if it’s a now and again thing (use https://crontab.guru/)

so do (remember no sudo this is your account)

crontab -e

go to the bottom of the file and add the following changing the cron to the one you want this example I am using 25 minutes */25 * * * *.

#Auto fetch keys from github every 25 mins
*/25 * * * * bash ~/.ssh/ssh-key-sync.sh

save it and your done.

sources

https://askubuntu.com/questions/1269493/ubuntu-server-20-04-1-lts-not-all-disk-space-was-allocated-during-installation

404invalid-user avatar
404invalid-user
Someone who does a lot of coding in js and can't write a readable blog to save their life.