Linux System Management

Processes

Networking

IP Configuration

Firewall

Uncomplicated Firewall (UFW) is a simple to use tool which allows you to set up firewall rules in less than 5 minutes.

sudo -s
apt-get install ufw
# --------------------
# This says that it will allow any outgoing connections on port 22 using the TCP protocol
ufw allow out 22/tcp 

# This allows all traffic on port 22 TCP/UDP
ufw allow 22

# This will deny ALL outgoing connections
ufw default deny outgoing 

By default, UFW will create a set of IPv4 and IPv6 - it is recommended that you delete whichever one you don't use.

Automation

There are tasks that we might do every time we start our system or every so often - like backing up folders, starting an application or multiple applications, or running scripts. Instead of doing it manually, Linux provides a process called Cron which we can utilise to automate these boring tasks and do them for us.

Crontabs

A crontab is a file that's utilised by the cron process to execute each line of instructions. Crontabs need 6 values in-order to work:

TryHackMe - Linux 3

For example, if we wanted to start a script called update_repos.sh every Friday, we would do:

* * * * 5 bash /home/username/update_repos.sh >/dev/null 2>&1

We can use a tool like Crontab Generator to make these for us since memorising the positions is a hassle and we like things easy right? The asterisks represent NULL inputs if we don't want to include additional values.

Creating & Editing a crontab

Enough with the boring stuff, let's look at how to create our own crontabs. Start by opening your terminal and executing crontab -e

no crontab for USER - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

Choose 1-4 [1]:

You might get this on first launch, select 1 if you want to go with nano, I prefer Vim so I'll use the second option. Scroll down to the bottom of the list and create a new line by hitting the return key (Enter). Now, go to Crontab Generator and create a process to automate!

Once you're done, click generate and paste the output into your crontab editor

Press Ctrl + X to save on Nano, or :wq on Vim. That's it! If you want to remove your saved crontabs, you can run crontab -r.

Last updated