du_setup
du_setup copied to clipboard
feat: auto-whitelist SSH IP in Fail2Ban and deduplicate entries
When setting up Fail2Ban, users connecting via SSH risk accidentally locking themselves out if their IP is not on the ignoreip list. Automating the addition of the user's SSH IP to the ignoreip list can help eliminate this possibility while also reducing potential lockout due to a misconfiguration/typo.
Additionally, if IPs are added manually, the ignoreip list can accumulate duplicate entries, making the configuration cluttered and potentially harder to manage.
I propose two enhancements to the Fail2Ban setup process:
- Automatic SSH IP Whitelisting:
- The script should detect the IP address of the current SSH session (from the
$SSH_CONNECTIONvariable). - It should then prompt the user, asking if they want to add this detected IP to the Fail2Ban
ignoreiplist. This provides a convenient way to prevent accidental lockouts.
- The script should detect the IP address of the current SSH session (from the
ignoreipList Deduplication:- Before writing the jail.local configuration, the script should process the array of IPs to be ignored and remove any duplicate entries. This ensures the final
ignoreiplist is always clean.
- Before writing the jail.local configuration, the script should process the array of IPs to be ignored and remove any duplicate entries. This ensures the final