> For the complete documentation index, see [llms.txt](https://blog.securescape.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.securescape.cc/fundamentals/linux-wip/linux-system-management.md).

# 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.&#x20;

```bash
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:

| Value | Description                                     |
| ----- | ----------------------------------------------- |
| MIN   | What minute to execute at                       |
| HOUR  | What hour to execute at                         |
| DOM   | What **D**ay **O**f the **M**onth to execute at |
| MON   | What **M**onth **O**f the **Y**ear to execute a |
| DOW   | What **D**ay **O**f the **W**eek to execute at  |
| CMD   | The actual command that'll get executed         |
| \*    | NULL                                            |

[*TryHackMe - Linux 3*](https://tryhackme.com/room/linuxfundamentalspart3)

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

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

We can use a tool like [Crontab Generator](https://crontab-generator.org/) 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`&#x20;

```bash
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](https://crontab-generator.org/) and create a process to automate!

<figure><img src="/files/CthpGDlZXOxvkyS7F7Ao" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/JvIKXBJeSngNxTgtozxd" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/kAKhyLB7LncHXSwmLlKC" alt="" width="439"><figcaption></figcaption></figure>

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`.
