Most ransomware discussions focus on backups and endpoint detection. Those matter, but they activate after an attacker is already inside. The configs below stop ransomware at the OS and network layer—before encryption starts, before files disappear, before you're negotiating with criminals.
I've worked tickets where a single open RDP port or a default SSH config led to full server encryption. The pattern repeats: attacker finds an entry point, moves laterally, dumps credentials, then deploys the payload. Each of the seven hardening steps below closes one of those common entry points or choke points.
Disable unnecessary services and ports
Every listening service is a potential door. Ransomware actors scan for open RDP (3389), SMB (445), and misconfigured databases. If your server doesn't need RDP, turn it off at the OS level—not just in the firewall.
On Linux, list active services:
systemctl list-unit-files --type=service --state=enabled
Disable anything you don't recognize or need:
sudo systemctl disable <service_name>
sudo systemctl stop <service_name>
On Windows Server, open Services (services.msc) and set startup type to Disabled for Remote Desktop Services if you don't use RDP. For SMB, if you're not file-sharing internally, disable Server service entirely.
Close the corresponding ports in your firewall. Default-allow firewall rules are a gift to attackers.
Restrict SSH to key-based auth and specific IPs
Password-based SSH is brute-forced constantly. I've seen login attempt logs scroll past thousands of failed tries in a single day. Switch to public key authentication and disable password login entirely.
Edit /etc/ssh/sshd_config:
PasswordAuthentication no
PubkeyAuthentication yes
PermitRootLogin prohibit-password
Restart SSH:
sudo systemctl restart sshd
If your IP is static or you connect from a known range, add an allow rule in your firewall (iptables, ufw, or cloud security group). Drop everything else. This single change blocks the most common initial access vector for Linux servers.
For extra defense, move SSH to a non-standard port (not 22). Automated scanners often skip ports above 10000. Not security through obscurity alone, but it reduces noise and failed login attempts that can mask a real attack.
Enforce application whitelisting or execution control
Ransomware needs to run an executable. Application whitelisting stops unknown binaries from executing. On Linux, use a tool like fapolicyd or AppArmor. On Windows, use AppLocker or Windows Defender Application Control.
For a basic fapolicyd setup on RHEL-based systems:
sudo dnf install fapolicyd
sudo systemctl enable --now fapolicyd
Out of the box, fapolicyd allows execution from standard trusted paths like /usr/bin and blocks everything else. Adjust rules in /etc/fapolicyd/fapolicyd.rules if you run apps from non-standard directories.
On Windows Server, configure AppLocker via Group Policy. Create rules that only allow executables signed by trusted publishers or located in C:\Program Files and C:\Windows. Attackers often drop payloads in temp directories or user profiles; whitelisting stops those dead.
This won't catch every attack, but it blocks most opportunistic ransomware that relies on dropping an .exe in a writable directory and hoping it runs.
Set strict file permissions and disable script execution in temp
Ransomware payloads often land in /tmp, /var/tmp, or Windows %TEMP% directories. Mount /tmp with noexec to prevent execution:
Edit /etc/fstab and add or modify the /tmp line:
tmpfs /tmp tmpfs defaults,noexec,nosuid,nodev 0 0
Remount:
sudo mount -o remount /tmp
Do the same for /var/tmp if it's a separate mount.
On Windows, use Group Policy to block script execution in user temp folders. Set Software Restriction Policies or use Applocker path rules to deny execution from C:\Users\*\AppData\Local\Temp and C:\Windows\Temp.
Also lock down permissions on web directories. A PHP shell uploaded to a world-writable web root can download and execute ransomware. Set ownership to your web user (www-data, apache, nginx) and chmod files to 644, directories to 755. Never 777.
Deploy host-based intrusion detection
FIDS (File Integrity Detection System) tools like AIDE or Tripwire alert you when critical files change. Ransomware modifies thousands of files. AIDE catches that.
Install AIDE on Debian/Ubuntu:
sudo apt install aide
sudo aideinit
sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Run daily checks via cron:
sudo aide --check
Configure AIDE to monitor /etc, /usr/bin, /usr/sbin, and your web or application directories. Changes to these paths outside maintenance windows should trigger investigation.
For runtime behavior monitoring, install and configure auditd. Watch for suspicious process activity like rapid file access, privilege escalation attempts, or execution from unusual directories. A baseline auditd rule set:
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
sudo auditctl -w /etc/shadow -p wa -k shadow_changes
sudo auditctl -w /bin/ -p x -k bin_exec
Persist rules in /etc/audit/rules.d/audit.rules. Review logs in /var/log/audit/audit.log regularly or forward them to a SIEM.
Harden RDP and enable Network Level Authentication
If you must expose RDP, enable Network Level Authentication (NLA). NLA requires authentication before a full RDP session starts, blocking many automated exploits.
On Windows Server, open System Properties > Remote tab and check "Allow connections only from computers running Remote Desktop with Network Level Authentication."
Change the default RDP port from 3389 to something high (e.g., 49152-65535). Edit the registry:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber
Set it to a new decimal value, then restart the Remote Desktop Services.
Restrict RDP access by IP in Windows Firewall:
New-NetFirewallRule -DisplayName "RDP Restrict" -Direction Inbound -LocalPort 3389 -Protocol TCP -Action Allow -RemoteAddress 203.0.113.0/24
Replace the CIDR with your actual admin IP range. Deny all other sources. Better yet, disable RDP entirely and use SSH tunneling or a VPN for remote access.
Segment networks and limit lateral movement
Ransomware doesn't stop at one server. Once inside, attackers pivot to other machines using SMB, WMI, or RDP. Network segmentation contains the blast radius.
Create VLANs or subnets for different server roles: web servers, database servers, admin jump boxes. Apply firewall rules so web servers can't initiate connections to databases on ports other than MySQL/PostgreSQL. Databases can't talk to the internet at all.
On Linux, use iptables or nftables to restrict traffic between internal IPs:
sudo iptables -A FORWARD -s 10.0.1.0/24 -d 10.0.2.0/24 -j DROP
Allow only specific required flows:
sudo iptables -A FORWARD -s 10.0.1.10 -d 10.0.2.5 -p tcp --dport 3306 -j ACCEPT
On Windows, use Windows Firewall with Advanced Security to create inbound and outbound rules per network profile. Deny by default, allow explicitly.
Disable SMBv1 entirely across your network. SMBv1 has known exploits (EternalBlue) used by ransomware like WannaCry. On Windows:
Disable-WindowsOptionalFeature -Online -FeatureName SMB1Protocol
On Linux Samba servers, edit /etc/samba/smb.conf:
min protocol = SMB2
Restart Samba. No server today needs SMBv1.
What triggers a ransomware infection despite these configs?
Even with every config above, a compromised admin account with sudo or domain admin rights can bypass technical controls. The weakest link is often credential reuse, phishing, or unpatched software.
Patch your OS and applications weekly. Subscribe to security mailing lists for your stack. CVEs get exploited within days of disclosure, sometimes hours. An unpatched Exim vulnerability or an old WordPress plugin can hand an attacker a shell, and from there they deploy ransomware.
Use unique, strong passwords and enforce MFA for all admin access—SSH keys, RDP, web panels, database consoles. Store credentials in a password manager, not a spreadsheet.
Monitor your server's outbound traffic. Ransomware often calls home to a C2 server before encrypting. Unusual outbound connections to foreign IPs or newly registered domains are red flags. Tools like tcpdump, Wireshark, or cloud flow logs help spot this.
Finally, test your backups. Ransomware increasingly targets backup systems. Immutable or air-gapped backups are the last line of defense. If an attacker encrypts your server and your backups, no config will save you.
FAQ
Does disabling services affect performance?
No. Disabling unused services frees RAM and CPU cycles. You'll see a small performance improvement, not a penalty.
Can I enable password SSH temporarily for migrations?
Yes, but re-disable it immediately after. If you forget, you're exposed. Better to set up key auth on the new machine first.
Will AppLocker or fapolicyd break my custom apps?
Potentially, if your app runs from a non-standard path. Whitelist that path in your policy before deploying. Test in a staging environment.
How often should I run AIDE checks?
Daily via cron is standard. For high-value servers, consider hourly. Forward alerts to your monitoring system so you don't miss them.
Is changing the SSH or RDP port really effective?
It reduces automated scanning noise significantly. It's not a substitute for key-based auth or IP whitelisting, but it helps. Think of it as closing the blinds—doesn't stop a determined intruder, but discourages casual opportunists.
Start with SSH and firewall rules first
If you only have time for two changes today, disable password SSH and close unused firewall ports. Those two steps block the majority of server ransomware I've seen in support tickets. Add the other five configs over the next week. Hardening is layered; no single control is perfect, but together they make your server a hard target. Ransomware actors move to easier prey.
