Phase 1: Regain Access and Initial Assessment
- Disconnect the compromised machine from the internet immediately to prevent further attacker activity.
- Access your system through a secure, alternative method, such as a local console or a previously configured out-of-band management tool.
- Change the passwords for all user accounts, especially
rootand any accounts withsudoprivileges, using strong, unique passwords.
Important
Phase 2: Identify and Remove Malware/Backdoors
- Review system logs (e.g.,
/var/log/auth.log,/var/log/syslog) for unusual activity, unauthorised logins, or failed login attempts. - Check for unknown or suspicious processes using
ps auxand investigate any that seem out of place. Terminate malicious processes withkill -9 [PID]. - Scan your system for rootkits with tools like Rootkit Hunter (
rkhunter) or Chkrootkit (chkrootkit). - Inspect cron jobs (
crontab -l) for any scheduled tasks that you didn't create. - Examine system startup scripts and services that launch at boot (e.g.,
systemctl list-unit-files --state=enabled) for anything suspicious.
Good to know
Phase 3: Cleanup and Re-secure SSH
- Remove any unauthorised SSH keys from
~/.ssh/authorized_keysfor all users. - Review and harden your SSH configuration file (
/etc/ssh/sshd_config):- Disable password authentication (
PasswordAuthentication no). - Disallow root login (
PermitRootLogin no). - Change the default SSH port (
Port [NEW_PORT_NUMBER]). - Limit users who can connect via SSH (
AllowUsers username).
- Disable password authentication (
- Restart the SSH service (e.g.,
sudo systemctl restart sshd) to apply changes. - Consider setting up a firewall (e.g.,
ufworfirewalld) to only allow SSH connections from trusted IP addresses.
Tip
sshd_config file before making changes.Phase 4: Ongoing Monitoring and Best Practices
- Regularly update your operating system and all installed software to patch known vulnerabilities.
- Implement two-factor authentication (2FA) for SSH access for an extra layer of security.
- Regularly review system logs for any unusual activity.
- Use intrusion detection systems (IDS) such as Fail2Ban to automatically block suspicious IP addresses.
- Regularly back up your important data to an offsite location.
Good to know
Was this guide helpful?
Know someone who needs this? Send them the guide.
Written by
Jordan DicksonFounder, CyberSecurityGuides
Founder of CyberSecurityGuides, writing practical, jargon-free guides that help everyday people recover from and protect against online attacks.
Reviewed by CSG Security Engineers