From 7b7827fbae61466b32abf80960ae08e9a3e59747 Mon Sep 17 00:00:00 2001 From: Yee Kit Date: Thu, 30 May 2024 00:52:57 +0800 Subject: [PATCH] Update README & release.yml --- .github/workflows/release.yml | 4 +--- README.md | 45 ++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 816c33d..c220bd5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,8 +11,6 @@ on: - '*' pull_request: branches: [ "main" ] - tags: - - '*' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -39,7 +37,7 @@ jobs: - name: Create Release uses: ncipollo/release-action@v1.14.0 with: - tag: ${{ steps.version.outputs.version }} + tag: v${{ steps.version.outputs.version }} generateReleaseNotes: true makeLatest: true token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index c0b4618..d793f50 100644 --- a/README.md +++ b/README.md @@ -40,20 +40,22 @@ After which you can follow the instructions below to get started in installing t ## Getting Started -1. Install geoip packages: +1. Install required packages: ```bash $ sudo apt update $ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin geoipupdate ``` + - libmaxminddb0 libmaxminddb-dev – MaxMind Geolocation database libraries - mmdb-bin – binary. Program to call from the command line. Use this command to geolocate IP manually. - geoipupdate – package that assists in configuring and updating GeoIP2 / GeoLite2. -2. Clone the repo: +2. Download the latest release: ```bash -$ git clone https://github.com/xKhronoz/SSH-GeoIP-Filter.git +# Download the latest release +$ wget https://github.com/xKhronoz/SSH-GeoIP-Filter/releases/latest ``` 3. Copy the script to `/usr/local/bin`, add execute permissions and edit the `ALLOW_COUNTRIES` line to suit your needs: @@ -62,45 +64,60 @@ $ git clone https://github.com/xKhronoz/SSH-GeoIP-Filter.git $ cd SSH-GeoIP-Filter $ sudo cp ssh-geoip-filter.sh /usr/local/bin/ $ sudo chmod +x /usr/local/bin/ssh-geoip-filter.sh +``` + +4. Edit line *5* in `sshd-geoip-filter.sh` to countries that you want to allow ssh from, separated by space (if more than 1), in uppercase ISO country codes (e.g. `SG` for Singapore). + +```bash +$ sudo nano /usr/local/bin/ssh-geoip-filter.sh +``` -# Edit line '5' in `sshd-geoip-filter.sh` to countries that you want to allow ssh from: +```bash 4: # UPPERCASE space-separated ISO country codes to ACCEPT 5: ALLOW_COUNTRIES="SG" ``` -4. Update `/etc/hosts.allow` & `/etc/hosts.deny` +5. Update `/etc/hosts.allow` & `/etc/hosts.deny` ```bash -# After `sudo nano /etc/hosts.deny` add in this line: +sudo nano /etc/hosts.deny +# Add in this line: sshd: ALL -# After `sudo nano /etc/hosts.allow` add in this line: +sudo nano /etc/hosts.allow +# Add in this line: sshd: ALL: aclexec /usr/local/bin/ssh-geoip-filter.sh %a ``` -- Using aclexec in hosts.allow will allow the sshd service to take into account the exit code and abort connection attempts. -5. Setup Crontab to run geoipupdate periodically: +- Using aclexec in hosts.allow will allow the sshd service to take into account the exit code and abort connection attempts. + +6. Setup Crontab to run geoipupdate periodically: ```bash # Setup crontab as sudo $ sudo crontab -e +``` +```bash # Add in the lines below, change the timezone and schedule according to your preference (Use https://crontab.guru to get the schedule) -''' -# Disable mailing +# Disable mailing (Optional, remove MAILTO="" to enable mailing) MAILTO="" -# CRON TIMEZONE +# CRON TIMEZONE (Optional, change to your preferred timezone) CRON_TZ=Asia/Singapore # Update Maxmind GeoIP2 Database at 4am every thursday & saturday, logs to a file 0 4 * * 4,6 /usr/bin/geoipupdate -v >> /var/log/cron.log 2>&1 -''' ``` ## Compatible Operating Systems -Tested on Ubuntu 22.04 and Debian, should work the same on other similar linux systems. +Tested on Ubuntu 22.04 and Debian 11, should work on other similar linux systems running sshd. + +## TODO + +- [ ] Create a installation script to automate the installation process. +- [ ] Add support to edit the 'ALLOW_COUNTRIES' by user in installation script. ## Acknowledgements