aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: ae382ebf406ec484e6cc49b0cee57409d34318c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# matrix-monitoring
------

Some scripts to monitor your server and send data to matrix. Those scripts use a [matrix-sender](https://github.com/Oxbian/matrix-sender), another script I made to send message to matrix.

## Install

To install this project & load submodules, use:

```bash
git clone --recurse-submodules https://github.com/Oxbian/matrix-monitoring.git
```

Or you can use:
```bash
git clone https://github.com/Oxbian/matrix-monitoring.git
git submodule update --init --recursive
```

## Update

To get the latest update from this repo, you will need to run those commands in the matrix-monitoring folder:  

```bash
git stash
git pull origin main
git pull --recurse-submodules
git stash pop
```

Thanks to those commands you will be able to get the last update without losing your token & configurations.  

## Logwatch

First you need to configure matrix-sender, I recommend you to check the repo [matrix-sender](https://github.com/Oxbian/matrix-sender).  

After that you need to edit `logwatch.sh` to add the `matrix.sh` absolute path.  

Now you can add the script to your crontab, `sudo crontab -e`.  
```bash
0 0 * * * /home/oxbian/matrix-monitoring/logwatch.sh
```

## SSH Login

The script `login-notify.sh` will allow you to get a message when someone successfully open a SSH connection on your server.  

First, you will need to have matrix-sender configured, then add the path of matrix.sh in the `login-notify.sh` script.  

After that I recommand to create a symlink of this file in `/etc/ssh` and let the access to root only for security reason.

```bash
sudo ln -sf "$(pwd)/login-notify.sh" /etc/ssh/login-notify.sh 
sudo chown root:root /etc/ssh/login-notify.sh
```

After that you will need to add those lines in your pam configuration `/etc/pam.d/sshd`:

```bash
#Send a message on SSH connection
session optional pam_exec.so seteuid /etc/ssh/login-notify.sh
```

## Fail2Ban

First you need to configure matrix-sender, I recommend you to check the repo [matrix-sender](https://github.com/Oxbian/matrix-sender).  

After that you need to edit `Fail2Ban/matrix.conf` and change the absolute path to your `matrix.sh` script.

Once all this is done, you can copy the `jail.local` in your `jail.d` folder and `matrix.conf` in the `action.d` folder.

```bash
sudo ln -sf "$(pwd)/Fail2Ban/jail.local" /etc/fail2ban/jail.d/jail.local
sudo ln -sf "$(pwd)/Fail2Ban/matrix.conf" /etc/fail2ban/action.d/matrix.conf
```

After that just restart the fail2ban service and check for errors, and if you have some, fix them.

You will probably need to edit the jail.local script to your liking.

## Contributing

If you want to contribute, make a pull request with your contribution.  

## License

This project is under the GPLv3 license, you can use it in your project but not in closed sources ones.  
Sharing project is what make the world live, think about it.
ArKa projects. All rights to me, and your next child right arm.