Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Essential Linux commands every VPS owner should know. From file management to security — a practical reference guide.
Disclosure: This page contains affiliate links. If you purchase a hosting plan through one of our links, we may earn a commission at no extra cost to you. This helps support HostBeacons and allows us to continue producing free, in-depth content. We only recommend services we have personally tested or thoroughly researched.
I still remember the first time I logged into a VPS via SSH. The blinking cursor on that black terminal screen felt like standing at the edge of a cliff. No control panel, no friendly buttons — just me and the command line. If that sounds familiar, you are in the right place.
When you move from shared hosting to a virtual private server, you inherit real power and real responsibility. Nobody is going to restart your web server at 2 AM or clean up runaway log files for you. The good news is that you do not need a computer science degree to manage a VPS effectively. You need a working knowledge of a few dozen Linux commands, and that is exactly what this guide delivers.
I have organized everything into logical categories so you can bookmark this page and come back whenever you need a refresher. Every command includes a practical example you can run on your own server. Let us get started.
Before you can do anything useful on a Linux server, you need to know where you are and how to move around the filesystem. These three commands are the foundation of every terminal session.
This command tells you exactly where you are in the directory tree. When you first SSH into your server, you typically land in your home directory, but it never hurts to confirm.
pwd
# Output: /home/yourusernameOnce you know where you are, you need to see what is around you. The ls command lists files and directories. I almost always use it with flags for extra detail.
# Basic listing
ls
# Detailed listing with file sizes, permissions, and timestamps
ls -lah
# List only directories
ls -d */The -l flag gives you the long format, -a shows hidden files (those starting with a dot), and -h makes file sizes human-readable. Once you start using ls -lah, you will never go back to plain ls.
Moving between directories is something you will do hundreds of times a day. Here are the patterns I use most often.
# Move into a directory
cd /var/www/html
# Go up one level
cd ..
# Go back to your home directory
cd ~
# Go to the previous directory
cd -Managing files is the bread and butter of VPS administration. Whether you are deploying a website, editing configuration files, or cleaning up disk space, these commands are indispensable.
Always make a backup before you edit a configuration file. This habit has saved me more times than I can count.
# Copy a single file
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
# Copy an entire directory recursively
cp -r /var/www/html /var/www/html_backupThe mv command serves double duty. It moves files to a new location and renames them.
# Rename a file
mv oldname.conf newname.conf
# Move a file to another directory
mv backup.tar.gz /home/yourusername/backups/This one demands respect. There is no recycle bin on a Linux server. When a file is gone, it is gone.
# Remove a single file
rm unwanted-file.txt
# Remove a directory and everything inside it
rm -rf /var/www/old-site/
# Prompt before each removal (safer)
rm -i important-file.txtI strongly recommend pausing for a second before you run any rm -rf command. Double-check the path. Triple-check it if you are running as root.
File permissions control who can read, write, and execute files. Misconfigured permissions are one of the most common causes of “403 Forbidden” errors on web servers.
# Give the owner read, write, and execute; group and others read and execute
chmod 755 /var/www/html
# Make a script executable
chmod +x deploy.sh
# Set standard permissions for web files
chmod 644 /var/www/html/index.htmlWhen your web server cannot read files, it is often because the files are owned by the wrong user. The chown command fixes that.
# Change owner and group
chown www-data:www-data /var/www/html -R
# Change only the owner
chown yourusername file.txtMonitoring your server’s health is not optional — it is essential. These commands help you keep tabs on CPU usage, memory consumption, and disk space before small problems become outages.
The top command ships with virtually every Linux distribution and gives you a live view of running processes sorted by CPU usage. It is functional but not pretty.
# Launch the built-in process monitor
topI much prefer htop, which offers a color-coded, interactive interface. You can sort by memory, CPU, or process name, and you can kill processes directly from the interface.
# Install htop (Debian/Ubuntu)
sudo apt install htop
# Launch it
htopRunning out of disk space can bring your entire server to its knees. I check this regularly.
# Show disk usage in human-readable format
df -h
# Show only the root partition
df -h /If your VPS feels sluggish, memory is usually the first thing to investigate.
# Display memory usage in megabytes
free -m
# Display in human-readable format
free -hNeed to know what kernel version you are running or what architecture your server uses? This is the command.
# Show all system information
uname -a
# Show only the kernel version
uname -rYour VPS exists to serve content over a network, so understanding networking commands is critical. These tools help you test connectivity, download files, and troubleshoot connection issues.
The simplest way to check whether a host is reachable.
# Ping a domain
ping -c 4 google.com
# Ping your own server's IP
ping -c 4 203.0.113.10The -c 4 flag limits the test to four packets. Without it, ping runs indefinitely on most Linux systems.
I use curl constantly for testing APIs, checking HTTP response headers, and verifying that my sites are responding correctly.
# Fetch a webpage
curl https://example.com
# Show only the HTTP response headers
curl -I https://example.com
# Download a file
curl -O https://example.com/file.tar.gz
# Test an API endpoint
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/dataWhile curl is versatile, wget is purpose-built for downloading files and handles things like resuming interrupted downloads gracefully.
# Download a file
wget https://example.com/latest-release.tar.gz
# Resume a partially downloaded file
wget -c https://example.com/large-file.iso
# Download an entire directory recursively
wget -r -np https://example.com/docs/Knowing which ports are open and which services are listening is fundamental to both troubleshooting and security. The ss command is the modern replacement for netstat, but both are worth knowing.
# Show all listening ports with ss
ss -tulnp
# The older netstat equivalent
netstat -tulnp
# Show established connections
ss -t state establishedIf you see a port open that you do not recognize, investigate immediately. Unexplained listening ports can be a sign of compromise.
Processes are the heartbeat of your server. Knowing how to inspect them, stop them, and manage them through systemd is a non-negotiable skill for any VPS owner.
# Show all running processes with full detail
ps aux
# Find a specific process
ps aux | grep nginx
# Show processes in a tree format
ps axjfWhen a process misbehaves, you need to stop it. The kill command sends signals to processes.
# Gracefully stop a process (SIGTERM)
kill 12345
# Force kill a process that won't stop (SIGKILL)
kill -9 12345
# Kill all processes by name
killall php-fpmAlways try a graceful kill first. The -9 flag should be your last resort because it does not give the process a chance to clean up after itself.
Modern Linux distributions use systemd to manage services. The systemctl command is how you interact with it.
# Start a service
sudo systemctl start nginx
# Stop a service
sudo systemctl stop nginx
# Restart a service (useful after config changes)
sudo systemctl restart nginx
# Check the status of a service
sudo systemctl status nginx
# Enable a service to start on boot
sudo systemctl enable nginx
# Disable a service from starting on boot
sudo systemctl disable nginxAfter editing any configuration file for Nginx, Apache, MySQL, or any other service, you need to either restart or reload the service for changes to take effect. The reload option is preferable when available because it applies changes without dropping active connections.
# Reload without full restart
sudo systemctl reload nginxInstalling, updating, and removing software is something you will do frequently. The commands differ depending on your distribution.
If you are running Ubuntu or Debian, which covers the majority of VPS hosting setups, apt is your package manager.
# Update the package list
sudo apt update
# Upgrade all installed packages
sudo apt upgrade -y
# Install a new package
sudo apt install certbot -y
# Remove a package
sudo apt remove package-name
# Remove a package and its configuration files
sudo apt purge package-name
# Clean up unused packages
sudo apt autoremove -yIf your VPS runs CentOS, RHEL, AlmaLinux, or Rocky Linux, you will use yum or its successor dnf.
# Update all packages
sudo yum update -y
# Install a package
sudo yum install httpd -y
# Remove a package
sudo yum remove httpd
# Search for a package
yum search php
# With dnf (Fedora, RHEL 8+, AlmaLinux 9+)
sudo dnf install nginx -yWhichever package manager your distribution uses, make it a habit to run updates at least weekly. Unpatched software is one of the easiest ways for attackers to compromise a server.
A huge part of server administration involves reading log files and editing configuration files. These commands make that work manageable.
# Display a file
cat /etc/hostname
# Display with line numbers
cat -n /etc/nginx/nginx.confIf I had to pick one command that I use more than any other, it would be grep. It searches for patterns inside files and is invaluable for parsing logs.
# Search for a string in a file
grep "error" /var/log/syslog
# Case-insensitive search
grep -i "warning" /var/log/nginx/error.log
# Search recursively through a directory
grep -r "database_host" /etc/
# Show line numbers with results
grep -n "listen" /etc/nginx/sites-available/default
# Count the number of matches
grep -c "404" /var/log/nginx/access.logLog files can be enormous. You almost never need to read the entire thing. The tail command shows you the most recent entries, and its -f flag lets you watch a log file in real time.
# Show the last 20 lines of a file
tail -n 20 /var/log/syslog
# Follow a log file in real time (Ctrl+C to stop)
tail -f /var/log/nginx/access.log
# Combine tail and grep to watch for specific events
tail -f /var/log/auth.log | grep "Failed password"That last example is one I run frequently. It shows failed SSH login attempts in real time, which is a quick way to see if someone is trying to brute-force your server.
You will need to edit files directly on your server. Two editors dominate the Linux world.
nano is the beginner-friendly option. It shows keyboard shortcuts at the bottom of the screen, and it behaves more or less like a normal text editor.
# Open a file in nano
nano /etc/nginx/sites-available/defaultSave with Ctrl+O, exit with Ctrl+X. That is really all you need to know to be productive with nano.
vim has a steeper learning curve, but it is extraordinarily powerful once you learn it. At a minimum, you should know how to open a file, make edits, save, and quit — because vim is installed on virtually every server you will ever touch.
# Open a file in vim
vim /etc/nginx/sites-available/default
# Inside vim:
# Press 'i' to enter insert mode (so you can type)
# Press 'Esc' to exit insert mode
# Type ':wq' and press Enter to save and quit
# Type ':q!' and press Enter to quit without savingIf you are managing a VPS, security is your responsibility. These tools form the first line of defense. For a broader look at protecting your web properties, see our guide on how to secure your website.
UFW is the standard firewall management tool on Ubuntu and Debian. It provides a straightforward interface for controlling which ports are open to the internet.
# Enable the firewall
sudo ufw enable
# Allow SSH (do this BEFORE enabling, or you will lock yourself out)
sudo ufw allow 22/tcp
# Allow HTTP and HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Deny a specific port
sudo ufw deny 3306/tcp
# Check the current rules
sudo ufw status verbose
# Allow connections only from a specific IP
sudo ufw allow from 203.0.113.50 to any port 22A word of caution: always allow SSH access before you enable the firewall. I have seen people lock themselves out of their own servers by enabling UFW without an SSH rule in place. It is a mistake you only make once, but it is a painful one.
Fail2ban monitors your log files for repeated failed authentication attempts and automatically bans offending IP addresses. It is one of the most effective tools you can install on a VPS.
# Install fail2ban
sudo apt install fail2ban -y
# Start and enable the service
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
# Check the status of all jails
sudo fail2ban-client status
# Check the status of the SSH jail specifically
sudo fail2ban-client status sshd
# Manually unban an IP address
sudo fail2ban-client set sshd unbanip 203.0.113.50For custom configuration, create a local override file rather than editing the main config directly. This ensures your settings survive package updates.
# Create a local configuration file
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.localInside jail.local, you can adjust the ban time, the number of allowed retries, and which services to monitor. I typically set the ban time to one hour and the max retries to three for SSH.
Knowing individual commands is important, but the real power comes from combining them. Here are a few compound commands I use regularly in my own VPS management workflow.
# Find the 10 largest files on your server
du -ah / 2>/dev/null | sort -rh | head -n 10
# Check which process is using the most memory
ps aux --sort=-%mem | head -n 10
# Find and delete log files older than 30 days
find /var/log -name "*.log" -mtime +30 -delete
# Quick server health check
echo "=== Uptime ===" && uptime && echo "=== Disk ===" && df -h / && echo "=== Memory ===" && free -h && echo "=== Load ===" && cat /proc/loadavgThese one-liners become second nature after a while. I recommend keeping a personal cheat sheet — a plain text file on your local machine — where you save commands that you find yourself looking up repeatedly.
No. Start with navigation and file management. Those cover about 80 percent of what you will do day to day. Add networking and security commands as you get more comfortable. The goal is steady progress, not overnight mastery.
Most of these commands are perfectly safe to run. The ones that demand caution are rm -rf, chmod, chown, and anything run as root. If you are nervous, spin up a cheap test VPS or use a local virtual machine to practice. You can find affordable options in our best VPS hosting roundup.
apt is the package manager for Debian-based distributions like Ubuntu. yum (and its successor dnf) is the package manager for Red Hat-based distributions like CentOS, AlmaLinux, and Rocky Linux. They do the same job but use different syntax and different package repositories.
If you are just getting started, use nano. It is intuitive, and you can be productive immediately. Learn vim when you are ready for a more powerful editing experience, or when you find yourself working on servers where nano is not installed. There is no wrong answer here — the best editor is the one that does not slow you down.
Look for unfamiliar processes in htop or ps aux, unexpected open ports in ss -tulnp, strange entries in /var/log/auth.log, and files you do not recognize in web-accessible directories. Running fail2ban and a properly configured firewall dramatically reduces your risk. For a deeper dive, read our guide on how to secure your website.
At minimum, run sudo apt update && sudo apt upgrade -y (or the yum equivalent) once a week. For security-critical servers, consider enabling automatic security updates using the unattended-upgrades package on Ubuntu.
Use SSH key-based authentication instead of passwords, disable root login over SSH, change the default SSH port, and use fail2ban to block brute-force attempts. Combined with a properly configured firewall, these steps will protect you from the vast majority of automated attacks.
Managing a VPS through the command line might feel intimidating at first, but it gets easier remarkably fast. After a few weeks of regular use, most of these commands will be in your muscle memory. The terminal is not your enemy — it is the most direct and efficient way to control your server.
Start with the basics, build your confidence, and layer on more advanced commands as your needs grow. Every experienced sysadmin started exactly where you are now. The only difference between a beginner and an expert is time spent at the keyboard.
If you are still choosing a hosting provider for your first VPS, take a look at our best VPS hosting comparison. And if you want to understand the fundamentals before diving in, our what is VPS hosting guide covers everything you need to know.