The first time you SSH into a fresh VPS, all you get is a blinking prompt. No interface, no buttons. These are the basic commands anyone managing a VPS needs to know by heart.
I grouped them by actual task rather than listing them one after another, because that is much easier to remember.
Moving around and looking
pwd # which directory am I in
ls # list directory contents
ls -lah # detailed, with hidden files and readable sizes
cd /var/www # change directory
cd .. # go up one level
cd ~ # back to the home directory
clear # wipe the screen
ls -lah is the variant I use most: -l for the detailed list, -a to show hidden dotfiles (important, because .htaccess and .env are both hidden), -h to display sizes in KB and MB instead of raw bytes.
Reading file contents
cat config.php # print the whole file to the screen
less error.log # page through it, arrow keys, q to quit
head -n 20 access.log # first 20 lines
tail -n 50 error.log # last 50 lines
tail -f error.log # follow the log in real time
tail -f is the single most important debugging tool on this list. Open it in one window, use the website in another, and you watch errors appear the moment they happen.
For large files avoid cat, because it dumps everything at once. Use less and scroll.
Searching
grep "error" error.log # find lines containing a string
grep -i "database" config.php # case insensitive
grep -rn "wp_options" /var/www # recursive, with line numbers
find /var/www -name "*.log" # find files by name
find /var/www -type f -size +100M # find files larger than 100MB
The grep -rn pair is extremely useful when you need to know which file in a codebase holds a particular config string.
Working with files and directories
mkdir backup # create a directory
mkdir -p a/b/c # create a whole nested tree
cp file.txt file.bak # copy
cp -r folder/ backup/ # copy a directory
mv old.txt new.txt # rename or move
rm file.txt # delete a file
rmdir folder # delete an empty directory
rm -rf folder # delete a directory and everything in it
A serious warning about rm -rf: Linux has no recycle bin and does not ask twice. Mistyping rm -rf / or rm -rf / var/www (one extra space) wipes the server. Before pressing Enter on that command, read the path one more time.
A safe habit: run ls on the same path first to see exactly what you are about to delete.
Compressing and extracting
tar -czvf backup.tar.gz /var/www # compress a directory
tar -xzvf backup.tar.gz # extract
gzip file.sql # compress one file
gunzip file.sql.gz # decompress
zip -r site.zip folder/ # zip format
unzip site.zip # unzip
A way to remember the tar flags: create to make one, extract to open one, z for gzip, v to list the files as it goes, f to name the file.
Permissions
chmod 644 wp-config.php # owner reads and writes, everyone else reads
chmod 755 folder # directories need execute to be entered
chmod -R 755 /var/www # apply recursively
chown -R www-data:www-data /var/www # change ownership
The common rule for web servers: 644 for files, 755 for directories. Never use 777, that lets anyone on the server overwrite your files.
The number combines three permissions: read is 4, write is 2, execute is 1. So 6 = 4 + 2 is read and write, 7 = 4 + 2 + 1 is everything. The three digits apply to the owner, the group, and everyone else, in that order.
Watching resources
top # running processes, continuously updated
htop # nicer version, needs installing
df -h # free disk space
du -sh /var/www # how much this directory takes up
du -sh * | sort -h # rank subdirectories by size
free -h # RAM status
When a VPS suddenly goes slow, the first three commands I run are always top, df -h and free -h. Most incidents live in one of those three places: a process eating the CPU, a full disk, or exhausted RAM.
A full disk is the most overlooked culprit, and it is usually a log file that grew out of control. Running du -sh * | sort -h inside /var/log points at it immediately.
Managing services
systemctl status nginx # check status
systemctl restart nginx # restart
systemctl reload nginx # reload config without dropping connections
systemctl enable nginx # start automatically on boot
journalctl -u nginx -n 50 # last 50 log lines for the service
Prefer reload over restart when you only changed configuration: it picks up the new config without cutting off connections that are being served right now.
A few others worth knowing
passwd # change the current account's password
date # system date and time
whoami # which account am I logged in as
history # review commands you have typed
ln -s /source /link # create a symlink
echo $PATH # print an environment variable
which php # find the path to a command
uptime # how long the machine has been running
The two shortcuts that save the most time
Tab completes file and command names. Type cd /var/w and press Tab, and the shell fills in /var/www. It is faster and it prevents typos in paths.
Up arrow brings back the last command. Combined with Ctrl + R to search backwards through your history, you almost never have to retype a long command a second time.