How to Manage a VPS via Command

calendar_month October 01, 2025 schedule 12 min read visibility 6 views
person
Valebyte Team
How to Manage a VPS via Command

How to Manage a VPS via the Command Line?

Hey colleagues! I think each of us who has ever dealt with VPS hosting administration knows that the command line is our best friend, and sometimes our worst enemy. But fear not! In this article, we'll break down the main points of VPS management via the console, so that even the most novice Linux user feels confident. I'll share my experience, the mistakes I've made, and, of course, show you the most useful commands and techniques. We'll install software, configure services, monitor the system – in short, we'll do everything to make your VPS run like clockwork. This setup will be *fire*! Let's go!

Contents:

SSH Connection Basics for VPS

Как управлять VPS через командную строку? - A screenshot of a terminal window showing a successful SSH connection to a VPS, including the user prompt and server information.

Okay, so, the first thing we need to do is connect to our VPS. The most common method is SSH (Secure Shell). This is an encrypted connection that allows you to securely manage the server. Honestly, you can't get anywhere without SSH. I remember trying to work with a server without encryption at the very beginning... Don't do that. It's insecure. To connect, you'll need a terminal (on Linux or macOS) or PuTTY (on Windows). And, of course, the VPS IP address, login, and password (or an SSH key). Real talk, it's much better to use SSH keys than passwords. It's significantly more secure. Here's the command to connect via the terminal:
ssh user@192.168.1.100
Where `user` is your username, and `192.168.1.100` is the VPS IP address. Replace them with your own data, obviously. If you're using a non-standard port, add `-p` with the port number:
ssh -p 2222 user@192.168.1.100
If you're using an SSH key, you need to specify its path with the `-i` option:
ssh -i ~/.ssh/id_rsa user@192.168.1.100
Once connected, you'll see the server's welcome message and can start entering commands.

Setting up SSH Keys (for the Paranoid)

I'll be straight with you, setting up SSH keys is a bit of a hassle, but it's worth it. First, you need to generate a key pair (public and private) on your local computer:
ssh-keygen -t rsa -b 4096
This command will create two files: `id_rsa` (the private key, keep it secret!) and `id_rsa.pub` (the public key). Now you need to copy the contents of `id_rsa.pub` to the server. There are several ways to do this. The simplest is to use the `ssh-copy-id` command:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@192.168.1.100
This command will ask you for the server password, and then copy the public key to the `~/.ssh/authorized_keys` file. If the `ssh-copy-id` command is not available, you can do it manually:
cat ~/.ssh/id_rsa.pub | ssh user@192.168.1.100 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
After this, you can log into the server without a password. Boom! That's it! Now, to completely secure yourself, you can disable password login in the `/etc/ssh/sshd_config` file. Open it in a text editor (e.g., `nano` or `vim`):
sudo nano /etc/ssh/sshd_config
Find the line `PasswordAuthentication yes` and change it to `PasswordAuthentication no`. You can also change the SSH port to a non-standard one (e.g., 2222) to attract less attention from bots. After that, restart the SSH service:
sudo systemctl restart sshd
*Word of warning*: If you mess up the SSH configuration, you might lose access to the server. So always make backups and check your configuration before restarting the service. Been there, done that...
Authentication MethodSecurityConvenience
PasswordLowHigh
SSH KeyHighMedium (requires setup)

Security is always excessive until it's not enough.

Rob Joyce, NSA

Package Management and Software Installation

Как управлять VPS через командную строку? - A terminal showing the output of an `apt update` and `apt install` command, illustrating the process of installing a software package.

Alright, let's talk about package management. Honestly, this is one of the most important things you need to know how to do on a server. Package managers allow you to easily install, update, and remove programs. All Linux distributions use their own package managers. On Debian and Ubuntu – it's `apt`, on CentOS and Red Hat – `yum` or `dnf`. The deal is, I'll be showing examples for `apt` because it's the most common option. But the commands for `yum` or `dnf` are usually very similar. First, you need to update the list of available packages:
sudo apt update
This command will download package lists from the repositories. Then you can upgrade installed packages:
sudo apt upgrade
This command will upgrade all packages for which updates are available. If you want to upgrade only one package, specify its name:
sudo apt upgrade nginx
To install a new package, use the `apt install` command:
sudo apt install nginx
This command will install the `nginx` package and all its dependencies. To remove a package, use the `apt remove` command:
sudo apt remove nginx
This command will remove the `nginx` package but leave its configuration files. If you want to remove the configuration files as well, use the `apt purge` command:
sudo apt purge nginx

Working with Repositories (When Standard Ones Aren't Enough)

Sometimes, you might need to install a package that isn't in the standard repositories. In this case, you need to add a new repository. To do this, you either add its address to the `/etc/apt/sources.list` file or create a separate file in the `/etc/apt/sources.list.d/` directory. For example, to add the Node.js repository, you can create a file `/etc/apt/sources.list.d/nodesource.list` with the following content:
deb https://deb.nodesource.com/node_16.x focal main
deb-src https://deb.nodesource.com/node_16.x focal main
Where `focal` is the codename for your Ubuntu version. You can find it using the `lsb_release -c` command. After adding the repository, you need to update the package list and install the repository's signing key:
sudo apt update
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
Now you can install Node.js:
sudo apt install nodejs
*Pro tip*: Always verify the authenticity of repositories and signing keys. Don't trust unknown sources.
CommandDescription
sudo apt updateUpdates the package list
sudo apt upgradeUpgrades installed packages
sudo apt install <package>Installs a package
sudo apt remove <package>Removes a package
sudo apt purge <package>Removes a package and its configuration files

Software is a great combination between artistry and engineering.

Ready to Apply These Commands? Get Your Own VPS!

Start managing your server with full control and flexibility. Our VPS plans offer the power you need. — from €4.49/mo.

Choose VPS Hosting →
Bill Gates

Configuring and Managing Core Services

Alright, so, now let's talk about service configuration. Things get a bit more complex here, but don't worry, I'll help you figure it out. The deal is, every service has its own configuration file where its settings are stored. These files are usually located in the `/etc` directory. Let's look at configuring a few popular services.

Nginx Configuration (web server)

Nginx is a very popular web server. Its configuration file is located at `/etc/nginx/nginx.conf`. In this file, you can configure the main server parameters, such as the number of worker processes, connection limits, etc. But the main settings for websites are located in the `/etc/nginx/sites-available/` directory. To create a new site, you need to create a configuration file in this directory, for example, `/etc/nginx/sites-available/mysite.com`:
server {
    listen 80;
    server_name mysite.com www.mysite.com;

    root /var/www/mysite.com;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}
This setup is fire! This file tells Nginx to listen on port 80 (HTTP) and serve the `mysite.com` website from the `/var/www/mysite.com` directory. To activate the site, you need to create a symbolic link to this file in the `/etc/nginx/sites-enabled/` directory:
sudo ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/
After that, you need to restart Nginx:
sudo systemctl restart nginx
Now your site should be accessible at `mysite.com`. To check if Nginx is running, you can execute the command:
sudo systemctl status nginx
If everything is okay, you will see the message `active (running)`.

UFW Configuration (firewall)

UFW (Uncomplicated Firewall) is a simple and convenient firewall. It allows you to configure rules for incoming and outgoing traffic. To enable UFW, execute the command:
sudo ufw enable
Before enabling, you need to allow incoming SSH connections:
sudo ufw allow ssh
You can also allow incoming connections for HTTP (port 80) and HTTPS (port 443):
sudo ufw allow 80
sudo ufw allow 443
To view the current rules, execute the command:
sudo ufw status
*Word of warning*: Don't forget to allow incoming SSH connections, otherwise you will lose access to the server! Been there, done that...
ServiceConfiguration FileRestart Command
Nginx/etc/nginx/nginx.conf, /etc/nginx/sites-available/*sudo systemctl restart nginx
UFW/etc/ufw/ufw.confsudo ufw enable, sudo ufw disable

Simplicity is prerequisite for reliability.

Edsger W. Dijkstra

Monitoring VPS Resources

Real talk, resource monitoring is a must-have for any VPS administrator. Without monitoring, you won't know what's happening with your server until it crashes. Honestly, I don't understand how people work without monitoring. It's like driving a car blindfolded.

Using the Command Line for Monitoring

There are several useful commands in the command line for monitoring resources. The simplest is the `top` command:
top
This command shows a list of processes, sorted by CPU usage. You'll see information about CPU, memory, swap, etc. To exit `top`, press `q`. Another useful command is `htop`:
htop
`htop` is an improved version of `top` with a more user-friendly interface and the ability to sort by various parameters. If you don't have `htop`, install it:
sudo apt install htop
To monitor disk usage, you can use the `df -h` command:
df -h
This command shows information about occupied and free space on each disk. To monitor memory usage, you can use the `free -m` command:
free -m
This command shows information about occupied and free memory in megabytes. To view network usage, you can use the `iftop` command:
iftop
This command shows a list of connections and their speed. If you don't have `iftop`, install it:
sudo apt install iftop
*Pro tip*: Set up automatic monitoring using tools like Grafana and Prometheus. This will allow you to track resources in real-time and receive notifications about issues.

Example Script for Load Monitoring

Here's a simple script that shows current CPU, memory, and disk load:
#!/bin/bash

CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*id: \([0-9.]*\).*/\1/" | awk '{print 100 - $1}')
MEM_USAGE=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
DISK_USAGE=$(df -h / | awk '$NF=="/"{printf "%s", $5}')

echo "CPU Usage: $CPU_USAGE%"
echo "Memory Usage: $MEM_USAGE"
echo "Disk Usage: $DISK_USAGE"
Save this script to a file, for example, `monitor.sh`, and make it executable:
chmod +x monitor.sh
And run it:
./monitor.sh
This script will show the current CPU, memory, and disk load.
CommandDescription
topShows a list of processes sorted by CPU usage
htopAn improved version of top
df -hShows information about occupied and free disk space
free -mShows information about occupied and free memory
iftopShows network usage

Without data, you're just another person with an opinion.

W. Edwards Deming

File and Permissions Management

Okay, so, now let's talk about file and permissions management. Honestly, this is one of the most fundamental things you need to know to manage a server. The deal is, everything in Linux is a file. Even directories. So, knowing how to work with files is a must-have.

Basic File Management Commands

The most basic command is `ls` (list). It shows a list of files and directories in the current directory:
ls
To show all files, including hidden ones (starting with a dot), use the `-a` option:
ls -a
To show detailed information about files, including permissions, use the `-l` option:
ls -l
The `cd` (change directory) command allows you to navigate to another directory:
cd /var/www/html
To go back to the previous directory, use `cd ..`:
cd ..
To return to your home directory, use `cd` without arguments or `cd ~`:
cd
cd ~
The `mkdir` (make directory) command creates a new directory:
mkdir mydirectory
The `rm` (remove) command deletes a file:
rm myfile.txt
To delete a directory, use the `rmdir` (remove directory) command:
rmdir mydirectory
But `rmdir` only deletes empty directories. To delete a directory with all its contents, use the `rm -r` command:
rm -r mydirectory
*Word of warning*: Be careful with the `rm -r` command. It can delete anything without warning. Been there, done that... The `cp` (copy) command copies a file:
cp myfile.txt mycopy.txt
To copy a directory, use the `-r` option:
cp -r mydirectory mycopydirectory
The `mv` (move) command moves a file or directory:
mv myfile.txt /tmp
`mv` can also be used to rename files:
mv myfile.txt newfile.txt

Permissions (777 - evil!)

In Linux, every file has permissions for the owner, group, and other users. Permissions are denoted by three digits, each representing the sum of rights:
  • 4 – read permission
  • 2 – write permission
  • 1 – execute permission
For example, permissions `755` mean:
  • 7 – owner has read, write, and execute permissions (4+2+1)
  • 5 – group has read and execute permissions (4+1)
  • 5 – other users have read and execute permissions (4+1)
To change permissions, use the `chmod` (change mode) command:
chmod 755 myfile.txt
*Pro tip*: Never give `777` permissions to files or directories. It's insecure. Use the minimum necessary permissions.
CommandDescription
lsShows a list of files and directories
cdChanges to another directory
mkdirCreates a new directory
rmDeletes a file
cpCopies a file
mvMoves or renames a file
chmodChanges permissions

Give a man a program, frustrate him for a day. Teach a man to program, frustrate him for a lifetime.

Muhammad Waseem

Troubleshooting Common Issues and Debugging

Alright, let's talk about troubleshooting. Honestly, this is one of the most complex and crucial parts of VPS management. The deal is, something always breaks. And your job is to find and fix the problem.

Basic Debugging Tools

The first and most important tool is logs. Most services write their logs to files. They are usually located in the `/var/log` directory. For example, Nginx logs are in `/var/log/nginx/`. To view the last lines of a log, use the `tail -f` command:
tail -f /var/log/nginx/error.log
This command will show the last lines of the `error.log` file and update them in real-time. To view all logs for a specific period, use the `grep` command:
grep "error" /var/log/nginx/error.log
This command will show all lines containing the word "error". To view logs for systemd services, you can use the `journalctl` command:
journalctl -u nginx
This command will show the logs for the `nginx` service. To view logs from the last 10 minutes, use the `--since` option:
journalctl -u nginx --since "10 minutes ago"
To view logs in real-time, use the `-f` option:
journalctl -u nginx -f
If a service isn't starting, check its status using the `systemctl status` command:
systemctl status nginx

Need Even More Power? Upgrade to a Dedicated Server!

For ultimate performance and complete control, explore our SSD dedicated servers. Perfect for demanding projects.

Explore Dedicated Servers →

Share this post: