This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| system:ssh:security [2020/07/26 18:27] – ltsover9000 | system:ssh:security [2020/07/27 05:30] (current) – ltsover9000 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | # Live log: | ||
| + | ``` | ||
| + | watch -n 1 tail -n 50 / | ||
| + | ``` | ||
| + | |||
| + | # View successful login attempts | ||
| + | ``` | ||
| + | last | ||
| + | ``` | ||
| + | |||
| + | # Custom rolled commands | ||
| + | ``` | ||
| + | # /security | ||
| + | logs # general logs /w watch | ||
| + | llogs # live logs | ||
| + | ``` | ||
| + | |||
| + | # Locking down SSH Server | ||
| + | |||
| + | ## Whitelist and Blacklist IP addresses | ||
| Stop SSH service first! | Stop SSH service first! | ||
| Line 24: | Line 44: | ||
| ``` | ``` | ||
| - | Restrict IP address (whitelist): | + | ###Restrict IP address (whitelist): |
| ``` | ``` | ||
| sudo nano / | sudo nano / | ||
| Line 33: | Line 53: | ||
| ``` | ``` | ||
| - | Also, Open up / | + | ### |
| ``` | ``` | ||
| sudo nano / | sudo nano / | ||
| Line 43: | Line 63: | ||
| ``` | ``` | ||
| + | - https:// | ||
| + | - https:// | ||
| - | https:// | ||
| - | https://cloudcone.com/docs/article/how-to-restrict-ssh-access-only-to-specific-ips/ | + | ## Whitelist user names for login |
| + | ``` | ||
| + | sudo nano / | ||
| + | ``` | ||
| + | and add: | ||
| + | ``` | ||
| + | AllowUsers __userName__ | ||
| + | ``` | ||
| + | - https://www.oreilly.com/library/view/linux-security-cookbook/0596003919/ | ||
| + | ## Fail2Ban | ||
| + | |||
| + | https:// | ||
| + | |||
| + | ### Step 1 | ||
| + | ``` | ||
| + | sudo apt-get install fail2ban | ||
| + | ``` | ||
| + | ### Step 2: Setting up Fail2ban | ||
| + | Next, you need to configure fail2ban by creating a copy of ‘jail.conf’ to ‘jail.local’ | ||
| + | ``` | ||
| + | cd / | ||
| + | sudo cp jail.conf jail.local | ||
| + | ``` | ||
| + | |||
| + | ### Step 3 | ||
| + | Edit fail2ban configuration file using your favorite text-edito (I personally use ‘nano’) | ||
| + | ``` | ||
| + | sudo nano / | ||
| + | ``` | ||
| + | You can set IP address for fail2ban to ignore, IP addresses can be separated by space. | ||
| + | |||
| + | Bantime is the duration of time that you want fail2ban to block suspicious attempt, the value is in seconds | ||
| + | Maxretry is the number of failed attempts before fail2ban block the IP-address, in this case 3600 means 1-hour ban | ||
| + | |||
| + | ``` | ||
| + | # " | ||
| + | ignoreip = 127.0.0.1 192.168.1.1 | ||
| + | bantime | ||
| + | maxretry = 3 | ||
| + | ``` | ||
| + | |||
| + | ### Step 4 | ||
| + | Find ssh configuration under [ssh] heading, and enable it. | ||
| + | |||
| + | ``` | ||
| + | [ssh] | ||
| + | enabled = true | ||
| + | port = ssh | ||
| + | filter | ||
| + | logpath | ||
| + | maxretry = 3 | ||
| + | ``` | ||
| + | Similarly, you can also enable [ssh-dos] protection by changing the enabled value to “enabled = true” | ||
| + | |||
| + | ``` | ||
| + | [ssh-ddos] | ||
| + | enabled = true | ||
| + | port = ssh | ||
| + | filter | ||
| + | logpath | ||
| + | maxretry = 2 | ||
| + | ``` | ||
| + | ### Step 5 | ||
| + | After all is done, you may save the file, and (re)start the fail2ban service | ||
| + | ``` | ||
| + | sudo / | ||
| + | ``` | ||