Linux commands for VPS management: the essentials
Managing a Virtual Private Server with the right server commands is an essential topic for anyone who runs a VPS. Whether you are just starting with your first VPS or already have experience, mastering the right server commands makes the difference between efficient server management and endless searching for solutions. In this guide we cover all the essential commands you need to manage your VPS professionally.
Why knowledge of essential server commands is essential
Unlike shared hosting, where your hosting provider handles server management, with a VPS you are responsible for the management yourself. This requires basic knowledge of Linux commands for VPS to maintain your server, solve problems and implement security measures. Without this knowledge you run the risk of downtime, security problems and suboptimal performance.
The difference between shared hosting and VPS management
| Aspect | Shared Hosting | VPS (Unmanaged) |
|---|---|---|
| Software installation | Limited through a panel | Full control through the command line |
| Updates | By the provider | Carried out yourself through the terminal |
| Security | Basic, by the provider | Entirely your own responsibility |
| Troubleshooting | Through support tickets | Analysed yourself through logs and commands |
| Performance tuning | Not possible | Full control over the configuration |
Basic commands for file management
The most used Linux commands for VPS are those for managing files and folders. Here are the essentials that every VPS administrator should know:
Navigation and file overview
- pwd - shows the current folder you are in (print working directory)
- ls - lists all files and folders, use ls -la for details including hidden files
- cd - change folder, cd .. goes up one level, cd ~ goes to your home directory
- find - search for files based on name, size, date or type
- locate - a fast file finder through an indexed database
- tree - shows the folder structure visually as a tree diagram
Editing and moving files
- cp - copy files or folders (use -r for folders recursively)
- mv - move or rename files and folders
- rm - delete files (use -rf for folders, be very careful)
- mkdir - create a new folder (-p for nested folders)
- touch - create a new empty file
- chmod - change file permissions (e.g. chmod 755 file)
- chown - change the owner of a file or folder
Viewing and editing files
- cat - show the full content of a file
- less - view files with scrolling (handy for large files)
- head - show the first lines of a file (10 by default)
- tail - show the last lines, tail -f follows real-time updates (ideal for logs)
- nano - a simple text editor for beginners
- vim - a powerful text editor for advanced users
- grep - search files for specific text or patterns
User and permission management
Managing users and permissions is a crucial part of Linux commands for VPS knowledge, especially for the security of your server.
User management commands
- adduser - create a new user with a home directory and configuration
- usermod - change user settings (e.g. add to a group: usermod -aG sudo user)
- passwd - change a user's password
- deluser - remove a user from the system
- groups - show the groups a user belongs to
- su - switch to another user (su - for a full environment)
- sudo - run a command with root privileges
System information and monitoring
As a VPS administrator you need to know how your server is performing. These Linux commands for VPS give you insight into the system status.
Requesting system information
- uname -a - show full system information (kernel, architecture, hostname)
- hostname - show or change the server name
- uptime - show how long the server has been running and the average load
- df -h - show disk usage per partition in a readable format
- du -sh - show the size of files and folders
- free -h - show RAM usage (total, used, free, cache)
- lscpu - show CPU information
Process monitoring
| Command | Function | Use |
|---|---|---|
| top | Real-time process overview | A quick overview of CPU/RAM usage |
| htop | An improved version of top | Interactive process management with colours |
| ps aux | List all processes | A snapshot of running processes |
| kill | Stop a process by PID | kill -9 PID to force a stop |
| nice/renice | Process priority | Adjusting CPU priority |
| lsof | Open files per process | Diagnosing file locks |
Network management commands
Network-related Linux commands for VPS are indispensable for managing web servers, diagnosing connection problems and configuring network settings.
Network diagnostics
- ip addr - show all network interfaces and their IP addresses
- ping - test the connection to another system
- traceroute - show the path packets take to a destination
- nslookup/dig - run DNS queries for diagnosing DNS problems
- netstat -tulpn - show all open ports and which processes are listening on them
- ss -tulpn - a more modern replacement for netstat
- curl - make HTTP requests (handy for testing websites)
- wget - download files from the internet
Firewall management
- ufw status - show the current firewall rules
- ufw allow 80 - open port 80 for HTTP traffic
- ufw deny - block a specific port or IP address
- ufw enable/disable - switch the firewall on or off
- iptables -L - show the underlying iptables rules
Package management commands
Installing, updating and removing software is a core part of Linux commands for VPS knowledge. The commands differ per distribution.
Ubuntu/Debian (APT)
- apt update - refresh the package lists
- apt upgrade - install available updates
- apt install [package] - install a new package
- apt remove [package] - remove a package
- apt autoremove - remove unused dependencies
- apt search [term] - search for available packages
CentOS/AlmaLinux (DNF/YUM)
- dnf update - update all packages
- dnf install [package] - install a package
- dnf remove [package] - remove a package
- dnf search [term] - search for packages
Service management with systemd
Modern Linux distributions use systemd for managing services. These Linux commands for VPS are essential for starting, stopping and monitoring web servers, databases and other services.
The most important systemctl commands
- systemctl start [service] - start a service
- systemctl stop [service] - stop a service
- systemctl restart [service] - restart a service
- systemctl status [service] - show the status of a service
- systemctl enable [service] - start automatically at boot
- systemctl disable [service] - prevent automatic start
- journalctl -u [service] - view the logs of a specific service
Commonly used services on a web server
| Service | Description | Default port |
|---|---|---|
| nginx / apache2 | Web server | 80, 443 |
| mysql / mariadb | Database server | 3306 |
| php-fpm | PHP processor | 9000 (socket) |
| sshd | SSH server | 22 |
| fail2ban | Intrusion prevention | N/A |
| postfix | Mail server | 25, 587 |
Analysing log files
Logs are your most important source of information when diagnosing problems. Mastering log-related Linux commands for VPS is indispensable for troubleshooting.
Important log locations
- /var/log/syslog - the general system log
- /var/log/auth.log - authentication and security events
- /var/log/nginx/ - Nginx access and error logs
- /var/log/apache2/ - Apache access and error logs
- /var/log/mysql/ - MySQL/MariaDB logs
- /var/log/fail2ban.log - the Fail2ban activity log
Analysing logs with commands
- tail -f /var/log/syslog - follow the syslog in real-time
- grep "error" /var/log/nginx/error.log - search for errors
- awk '{print $1}' access.log | sort | uniq -c | sort -rn | head - the top 10 IP addresses in the access log
- journalctl --since "1 hour ago" - show logs from the past hour
- zcat /var/log/syslog.2.gz | grep "keyword" - search compressed older logs
Backup and compression commands
Making backups is crucial for your website backup strategy. Here are the Linux commands for VPS you need for this:
- tar -czf backup.tar.gz /path/to/folder/ - create a compressed archive
- tar -xzf backup.tar.gz - extract an archive
- rsync -avz source/ destination/ - synchronise files with an incremental copy
- scp file user@server:/path/ - copy files to another server through SSH
- mysqldump -u user -p database > backup.sql - make a database backup
- mysql -u user -p database < backup.sql - restore a database backup
Tips for efficient VPS management
Finally, a few tips to make your daily VPS management more efficient with Linux commands for VPS:
Aliases and shortcuts
Create aliases for frequently used commands in your .bashrc file. Examples are an alias for quickly viewing server load, restarting your web server or checking for available updates. This saves time and reduces typos.
Crontab for automation
Use crontab to automate tasks such as daily backups, log rotation and system scans. Take a look at our guide on setting up cron jobs for more information about automating tasks.
Mastering Linux commands for VPS is an investment that quickly pays for itself. With the commands in this guide you have a solid basis for managing your VPS professionally. As you gain more experience, you will discover that the command line is a powerful and efficient tool that you will not want to be without. Are you considering getting a VPS? Take a look at our comparison of renting a VPS: prices and options.
Advanced tips for daily VPS management
Besides the basic commands, there are advanced techniques that make your daily Linux commands for VPS work more efficient.
Shell scripting for automation
Shell scripts are powerful tools for automating repetitive tasks on your VPS. By combining a series of Linux commands for VPS in a script, you can carry out complex tasks with a single command. Start with simple scripts for backup tasks and gradually build up to more advanced automations. Use variables, conditional logic and loops to make your scripts flexible and reusable.
Tmux and screen: managing sessions
Tmux and screen are terminal multiplexers that allow you to manage multiple terminal sessions within a single SSH connection. This is particularly useful for long-running tasks: if your SSH connection is unexpectedly dropped, your processes keep running in the tmux session. You can reconnect later and continue exactly where you left off. This is indispensable for remote server management.
Pipelines and output redirection
The power of Linux lies in combining commands through pipes and redirection. With the pipe symbol you can use the output of one command as the input for the next. Output redirection allows you to save results in files for later analysis. These techniques make it possible to build complex data analyses and system reports from simple building blocks.
Linux commands for VPS: advanced file management
Effective file management through the command line is a core skill for VPS administrators. With the right Linux commands for VPS management, you can quickly find, analyse and manage files without a graphical interface.
Essential file management commands
| Command | Function | Example | Application |
|---|---|---|---|
| find | Search files by criteria | find / -name "*.log" -mtime +30 | Finding old log files |
| du | Disk usage per directory | du -sh /var/* | Analysing storage space |
| rsync | Synchronise files | rsync -avz /source/ /destination/ | Backups and migrations |
| tar | Archive files | tar -czf backup.tar.gz /data/ | Compression and archiving |
| chmod/chown | Change permissions | chmod 644 file.txt | Security and access |
| ln | Create symbolic links | ln -s /target /link | Configuration management |
The find command is particularly powerful for VPS management. Combine it with exec to carry out actions on found files, such as deleting temporary files older than 7 days. This helps keep your VPS clean and performant.
Linux commands for VPS: network diagnostics
With server problems, network diagnostics is often the key to finding the cause. With these Linux commands you can quickly identify and solve network issues on your VPS.
- netstat -tlnp - show all listening ports and which processes use them. Essential for checking whether services are running on the expected ports.
- ss -tlnp - a more modern replacement for netstat with faster output on systems with many connections.
- tcpdump - capture network traffic for analysis. Handy when debugging connection problems or investigating suspicious traffic.
- dig and nslookup - test DNS resolution to diagnose domain problems. Check whether your domain points to the correct IP address.
- traceroute - follow the path of network packets to a destination. Identify where delays or blockages occur.
- iftop - a real-time bandwidth monitor per connection. Indispensable for seeing which connections use the most bandwidth.
These commands are also useful when setting up server monitoring. By running network diagnostics regularly, you can spot problems before they reach your website visitors.
Automation with Bash scripts on your VPS
Carrying out repetitive tasks manually is error-prone and time-consuming. With Bash scripts you automate common VPS management tasks and save valuable time.
Commonly used automations for VPS management are:
- Automatic backups - a script that backs up your database and files daily to an external location.
- Log rotation and cleanup - automatically delete old log files to keep disk space free.
- Health checks - check whether services are running and restart them automatically on failure.
- Security scans - daily scans for rootkits, malware and unauthorised file changes.
- SSL certificate renewal - automatic renewal of Let's Encrypt certificates with cron jobs.
Use cron for scheduling automated tasks. Edit the crontab with crontab -e and add your tasks in the standard cron format. Do not forget to write the output of your scripts to a log file so that you can analyse problems. Combine your scripts with the VPS security checklist for fully automated and secure management of your server.
Linux commands for VPS: process management and troubleshooting
Managing processes is a daily task in VPS management. With the right Linux commands you can quickly find out which processes are using resources, restart stalled services and monitor overall server health.
The commands top and htop show real-time CPU and memory usage per process. Htop is the more user-friendly variant with colours and mouse support, but it is not always pre-installed. With ps aux you list all running processes, and in combination with grep you can filter specific processes. The kill command sends signals to processes: SIGTERM (15) asks a process to shut down cleanly, while SIGKILL (9) ends the process by force. Always use SIGTERM first and only SIGKILL as a last resort.
Systemd is the init system on modern Linux distributions and manages all services on your VPS. With systemctl start, stop, restart and status you manage services. With journalctl you view the logs of specific services. Combine these commands with the automation through Bash scripts discussed earlier to set up a robust management process.
Linux commands for VPS: disk management and storage optimisation
Disk space is a finite resource on your VPS and unexpectedly full disks cause crashes and data loss. With these Linux commands for VPS management, you keep your storage space under control and prevent problems.
The command df -h shows disk usage per partition in a readable format. Use du -sh in combination with specific directories to find the biggest space users. Log files are often the culprit when disks fill up; check the /var/log directory regularly. The command ncdu (NCurses Disk Usage) offers an interactive interface to navigate through your file system and quickly identify large files and directories. Set up warnings when disk usage goes above 80%, so that you have plenty of time to clean up or expand the storage capacity before it becomes a problem.
Linux commands for VPS: security commands
Besides file management and network diagnostics, there are specific Linux commands that are essential for the security of your VPS. With these commands you monitor the security of your server and detect suspicious activity.
The command last shows an overview of all recent login attempts on your server, including the time, source IP and session duration. With lastb you view failed login attempts, which is useful for identifying brute-force attacks. The command who shows who is currently logged in to the server. Use w for a more extensive overview that also shows what each logged-in user is doing.
To check open ports and listening services, use ss -tlnp or the older netstat -tlnp. Compare the output regularly with your expected configuration: unexpectedly open ports or unknown services are a warning sign. The command lsof -i shows all network connections per process, which helps identify suspicious outgoing connections. Integrate these security commands into your daily routine or automate them through scripts that generate a daily security report and send it to your email.