r/linuxadmin • u/newworldlife • Mar 04 '26
Watching SSH activity in real time (besides fail2ban) - curious how others handle this
I run a couple of small VPS servers and noticed something recently.
Fail2ban does a great job blocking brute-force attempts, but sometimes when I look through the logs later I still see random SSH probes - things like a new IP touching the server once or someone trying a weird username.
Usually I only notice it after digging through auth.log.
So I wrote a small script that just watches the SSH log in real time and highlights things like:
- new IPs hitting SSH
- repeated failed login attempts
- unexpected usernames
Nothing fancy. Just something that helps me notice activity right away instead of finding it later in the logs.
Curious what others do for this.
Do you watch SSH activity in real time, or do you mostly rely on tools like fail2ban?
76
u/TableIll4714 Mar 04 '26
I only allow public key authentication, no password auth, and then stop worrying about it and only check logs when there’s a problem
13
u/franktheworm Mar 04 '26
Going to sound like a dig, but it isn't. I just don't expose SSH to the internet, ever. Problem solved.
I will happily concede that there are plenty of cases where that's not an option though and going a bit deeper than fail2ban is logical. You've landed on some sane things to look for there.
2
u/xagarth Mar 05 '26
Don't care at all u less it's dosing.
2
u/KlausBertKlausewitz Mar 06 '26
Someone else using port knocking using knockd + knock to secure their SSH?
16
u/FormerlyUndecidable Mar 04 '26
Who cares? Let them knock all they want.
8
u/z3rogate Mar 04 '26
We use https://github.com/crowdsecurity/crowdsec an a grafana dashboard with combination of Prometheus
15
u/awesome_pinay_noses Mar 04 '26
I only enable ssh on lab environments and when I do, I change the port to a high number, ie 65000.
Drops ALL the noise.
9
u/Kilobyte22 Mar 04 '26
I simply don't care at all. I don't watch logs, I don't have fail2ban. And SSH runs on default port (I really hate it when someone changes the port). I only permit key auth and trust openssh.
1
u/luciddr34m3r Mar 04 '26
greynoise.io does this kind of thing and offers a lot of it for free
1
u/circularjourney Mar 04 '26
I rate limit connections via nftables and use public key auth.
I never got comfortable with installing fail2ban code. I'm a code minimalist.
6
u/dev_all_the_ops Mar 04 '26
Tailscale. Block ssh on public internet, only allow over vpn
4
u/Tall-Introduction414 Mar 04 '26
Yeah, port 22 is toast. In addition to the other suggestions, like key only authentication, changing the port number eliminates like 99% of the brute force attempts.
2
u/Special-Original-215 Mar 04 '26 edited Mar 04 '26
For ones exposed (not ssh) I set my fail2ban to 1yr jail
There's also paid Blumira which monitors more things but expensive
2
u/kuadhual Mar 04 '26
One or two (virtual) server? SSH port knocking.
Entire server farm? No SSH port open to the internet. Access SSH through VPN.
2
u/reviewmynotes Mar 04 '26
I use SSHguard, which seems to be similar to fail2ban, and have dabbled with crowdsec. I plan to get crowdsec into my environment on a larger scale when I have some time to focus on it. I think it might be interesting to you.
I also log the number of concurrent SSH connections on each host using Xymon, so I can look for suspicious activity after the fact if I ever need to.
If you can afford to switch to only allowing ssh keys, that could help you, too.
Lastly, there are always going to be failed attempts. My advice is to respond to that fact proportionally to the risk.
2
u/gmuslera Mar 04 '26
Many years ago used to have logwatch, that mailed me unexpected things in the logs I configured it to watch. The passwords attempt part is something that had been on internet for decades, you solve that only letting login with public/private keys, but there might be activity beyond that (i.e. exploiting a bug in ssh or in other exposed service), and just watching who are trying to connect using passwords may not protect you against that.
2
u/gnwill Mar 05 '26 edited Aug 18 '26
Physical rustic pillow feather many sip
This post was anonymized with Redact
2
u/spidireen Mar 04 '26
On the VPS systems I run, SSH is both keys-only and Tailscale-only.
1
u/oldmanwillow21 Mar 04 '26
A HIDS like ossec does exactly this. I just use a high port for my own stuff but have deployed this into company environments.
1
u/bhagatbhai Mar 04 '26 edited Mar 04 '26
All major public cloud providers have firewall options. I just block all the traffic on port 22 that is not coming from my IP. That said you do have to be fortunate enough to get an IP from your ISP that doesn't change frequently. Otherwise, it would be a chor change firewall rule very often.
However, on the flip side for the stuff that I have running at home, I only expose it to the internet while I am away from home. And that too, only allows authentication with the public key. I have fail2ban. But you probably already know that it won't block every attempt. So, if your configuration isn't solid, then something could slip thru if you only rely on fail2ban.
1
u/NoDoze- Mar 04 '26
Sounds like your not creating a fail2ban filter to block these other activities.
1
u/MartinMystikJonas Mar 04 '26
Use key auth instead (or together) with password login.
Allow login only from trusted IPs if possible (on network level).
Use non standard ssh port to block basic vulnerability scanning bots.
Strict fail2ban rules with recidive rules.
1
u/trunksta Mar 04 '26
Fail2ban works pretty reliably but you can use a VPN instead and just not expose ssh (probably most secure option)
For most vps I'm fine with setting custom port+ fail2ban but if I wanted higher security I'd go the VPN route
1
u/Kommenos Mar 04 '26
I expose the service meant to be exposed to the internet.
I don't check because it's all noise. If someone can brute force an SSH key I have bigger problems.
1
u/-pooping Mar 04 '26
I use elastic with a custom dashboard that i never look at as i dont publish ssh externally.
1
u/PirateCaptainMoody Mar 04 '26
I have the grafana alloy agent installed and watching the auth and fail2ban log files. I have a dashboard that shows login attempts, successes, and bans, and an alert for particularly high spikes in failed login attempts.
I also have an alert for ANY failed login attempts for my known usernames, as it would be unusual for an attacker to know them.
1
u/tuxsmouf Mar 04 '26
I use ossec and I created a rule sending me an email with each successful ssh authentication.
Every morning, a script is executed with a summary sent by email. In it, there is the result of "last -10".
1
u/srakken Mar 04 '26
Meh only allow public key auth and only allow access through VPN. I don’t trust leaving privileged ports exposed. All it would take is some RCE security bug that you don’t get patched on time to be a problem. With how fast AI is these days they probably already have a catalog of systems with exposed ssh ports.
1
u/necrohardware Mar 04 '26
Change port to smth random and high and 90+% of scanner will not check it and you won't get spammed with logs. Naturally only pubkey and a custom username.
1
u/olinwalnut Mar 04 '26
I expose SSH to the internet from my home lab, but it’s key only, firewalled off to only allow specific IPs (like from my parents house back to mine for example) and if I need to get in remotely in a rare instance where I can’t VPN into my network, I have knockd in place for the secret handshake to allow the “new” IP for 10 seconds which is more than enough time for me to SSH in and then after those 10 seconds expire, the new IP is removed from my firewall but since my connection was already established, I’m good to do what I need to do.
I check logs maybe once a week on the weekends when the wife and dog are still in bed just to make sure nothing suspicious has come through.
1
u/kai_ekael Mar 04 '26
Might look into logcheck for log review, my personal preference.
1
u/mysterytoy2 Mar 04 '26
Ah, let the games begin. I've had plenty of fun messing with the hackers.
1
u/-chonk- Mar 04 '26 edited Mar 04 '26
Use CyberArk or similar to broker SSH connections so that all activity is recorded and multifactor authentication can be enforced. Globally lock SSH authentication mechanisms (password, pubkey, gasps, etc). Allow authentication from CyberArk, using match statements in sshd_config. It may be overkill for some, but it works for my environment.
1
u/benbutton1010 Mar 07 '26
I made a Grafana dashboard to see all the dumb stuff bots try, then I let them have at it. High score is ~35,000 total attempts in 7d.
1
u/Available-Skirt-5280 Mar 07 '26
Save yourself the trouble and just host ssh on a different port
1
u/hakube Mar 07 '26
We generally use bastion hosts for everything, connected via VPN back into the target network(s).
To get to the bastion host we use wireguard or use port knocking to open the ssh port to the remote admin. zero attempts. Logs are silent. I sleep well.
0
u/s1lv3rbug Mar 05 '26
How come u have unknown hosts hitting ur ssh server? R u accessing ssh with password? Thats a bad idea. You should restrict only known IPs to ssh port and drop all other connections and use ssh keys.