A few months ago, one of my websites started loading really slowly. I was hosting it on a Linux VPS, and everything had been fine for weeks. Then, out of nowhere, it felt like the whole server had slowed to a crawl. At first, I thought it was just a traffic spike. But after checking, I saw the CPU usage was almost 100%. Something was wrong.
Have you ever had that happen? Maybe your VPS is lagging. Maybe your website crashes or your SSH session is super slow. These are often signs that your CPU is working too hard.
In this guide, I’ll help you find out why your Linux VPS is using too much CPU. I’ll also show you how to fix it — step by step.
What Is CPU Usage?
Let’s keep it simple.
CPU stands for Central Processing Unit. It’s the brain of your server. It runs your code, handles traffic, and processes everything from commands to website requests.
CPU usage is how much of that brain power is being used.
So if your CPU usage is 90% or more for a long time, your server may feel slow, unresponsive, or even crash.
What Causes High CPU Usage?
There are many possible causes. Here are a few common ones I’ve seen on my own servers:
- A program is using too much processing power.
- A background process is stuck or looping.
- A bad script (like a broken cron job) is running nonstop.
- Too many people are visiting your website at once.
- Your website is under attack (yes, it happens).
- The VPS plan is too small for your needs.
Sometimes it’s a mix of these.
Have you checked your VPS dashboard and seen a red warning or spike in CPU usage? Let’s dig in and figure it out.
Step 1: Log in to Your VPS
First, you need to log in to your server using SSH. If you’re on Windows, use PuTTY. If you’re on Mac or Linux, just use the terminal.
Open your terminal and type:
ssh root@your_server_ip
Replace your_server_ip
with your actual server IP address.
If you can’t log in because it’s too slow, try rebooting from your hosting panel (like Vultr, DigitalOcean, or Linode). Then log in right away.
Step 2: Use top
or htop
to See What’s Happening
Once you’re logged in, run this command:
top
This will show a live list of processes using your CPU and memory. Look at the %CPU
column. The top processes will be listed at the top.
Here’s what to look for:
- A process using 80% or more CPU.
- The name of the process (like
apache2
,mysql
,php
, orpython
). - How many processes are running at once.
If you see something like php
using a lot of CPU, your website or app might be the issue.
Want a better view? Try this:
apt install htop
htop
htop
is a more colorful and easy-to-read version of top
. It lets you scroll and sort processes better.
Step 3: Stop the Problem Process
Once you know which process is eating the CPU, you can stop it.
Let’s say you see a process with ID 1234 using a lot of CPU. You can stop it like this:
kill -9 1234
But be careful — only kill a process if you’re sure it’s safe. For example, don’t kill a database process unless you know it’s stuck.
If the problem keeps coming back, it’s time to dig deeper.
Step 4: Check Web Server and App Logs
If your server runs websites, the problem might be in your web app.
Check logs here (depending on your web server):
- Apache logs:
tail -n 50 /var/log/apache2/error.log
- Nginx logs:
tail -n 50 /var/log/nginx/error.log
- PHP logs:
tail -n 50 /var/log/php7.x-fpm.log
Look for errors, warnings, or repeated requests.
If you see one IP making thousands of requests per minute, it could be a bot or an attack. That would explain high CPU usage.
Step 5: Check Cron Jobs
Cron jobs are scheduled tasks that run automatically. But sometimes they run too often or get stuck.
To view your cron jobs:
crontab -l
Make sure you don’t have a job running every minute if it takes 5 minutes to complete. That causes overlap and spikes in CPU.
I once had a backup script running every 10 minutes that took 12 minutes to finish. The CPU never got a break.
Step 6: Check for Malware or Bots
Sometimes, the problem isn’t from you. Hackers often try to use your server to mine crypto or send spam.
Here’s what I do to check:
- Scan your system:
apt install rkhunter rkhunter --check
- Check for suspicious processes:
ps aux | grep -i miner
Also, check if your website is being hit by bots:
tail -f /var/log/nginx/access.log
If you see the same IP making hundreds of requests, block it:
ufw deny from 192.168.1.100
Replace the IP with the one you want to block.
Step 7: Upgrade or Optimize
Sometimes your VPS is just too small. If you’ve tried everything and your CPU is still spiking, consider upgrading your plan.
More CPU cores and more RAM give your apps room to breathe.
Or you can optimize your current setup:
Ways to optimize and lower CPU usage:
- Use caching (like Redis or a CDN).
- Compress images and files.
- Use a lightweight web server (like Nginx).
- Limit cron jobs and background tasks.
- Use tools like
fail2ban
to block bad traffic.
Two Quick Lists
Common Reasons for High CPU:
- Too many PHP requests
- Stuck cron jobs
- Bot attacks or scraping
- Bad code or infinite loops
- Malware or crypto miners
- Heavy database queries
Simple Tools That Help:
htop
– shows system usageiotop
– checks disk usagerkhunter
– scans for malwareufw
– simple firewalllogwatch
– summarizes logs
Wrapping Up
I’ve had days where my whole server slowed down, and I didn’t know why. I’d restart it and hope it would fix itself. But now I know how to check htop
, look at logs, and spot trouble before it gets worse.
Have you had a time when your server was slow and you didn’t know what to do?
The more you use these tools, the easier it gets. You don’t need to be a pro to spot high CPU usage. Just log in, look around, and take action.
High CPU usage doesn’t have to be scary. Most problems can be fixed with a few simple steps. And if you ever feel stuck, reach out for help — or just take a break and try again later.
Your Linux VPS will thank you.