A Linux server has no desktop, no start menu and no mouse. Everything happens in a terminal, and that can feel intimidating the first time you log in. The good news is that day-to-day administration rests on a fairly small set of commands. Once you know them, you can find your way around, edit configuration, install software, restart services and work out why something has stopped.
This guide walks through those commands in the order you will need them. The examples use Ubuntu 24.04 and Debian 12; where AlmaLinux or Rocky Linux differ, that is pointed out. If you have not logged in yet, start with how to connect to a Linux VPS with SSH.
Reading the prompt and a command
When you log in you see a prompt such as deploy@web01:~$. That is the user, the hostname and the current directory (~ means your home directory). A $ at the end means a normal user; # means you are root, so take extra care.
A command is a program name, optional flags and arguments:
ls -l /var/log
Here ls is the program, -l is a flag (long format) and /var/log is the argument. A few habits save a lot of typing:
- Tab completes file names and commands. Press it twice to see all options.
- Up arrow recalls previous commands;
historylists them. - Ctrl+C stops the running command; Ctrl+L clears the screen.
man lsopens the manual;ls --helpgives a shorter summary.
Moving around the file system
Everything on Linux lives in a single tree starting at /. Three commands get you around:
pwd # where am I?
ls -lah # list everything here, including hidden files, with readable sizes
cd /etc/nginx # go to a directory
cd .. # one level up
cd ~ # back to your home directory
cd - # back to the previous directory
The directories you will visit most often on a server:
| Directory | What is there |
|---|---|
/etc | Configuration files for the system and services |
/var/log | Log files |
/var/www | Website files, by convention |
/home | Home directories for normal users |
/tmp | Temporary files, cleared on reboot |
Working with files and directories
mkdir -p /var/www/example.com/public # create a directory (and any parents)
touch notes.txt # create an empty file
cp nginx.conf nginx.conf.bak # copy
mv old-name.txt new-name.txt # move or rename
rm notes.txt # delete a file
rm -r old-folder # delete a directory and its contents
Warning: Linux has no recycle bin.
rm -rfdeletes without asking, and a stray space in a path can remove far more than you meant to. Runlson the path first and keep backups.
To read files without changing them:
cat /etc/os-release # print a short file
less /var/log/syslog # scroll through a long file (q to quit, / to search)
head -n 20 access.log # first 20 lines
tail -n 50 error.log # last 50 lines
tail -f error.log # follow new lines as they are written
grep -i "error" error.log # lines containing "error", case-insensitive
grep -rn "server_name" /etc/nginx/ # search recursively, with line numbers
find /var/www -name "*.php" -mtime -1 # PHP files changed in the last day
For editing, nano is the easiest editor to start with. Ctrl+O saves and Ctrl+X exits. Make a copy before you change an important file:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo nano /etc/ssh/sshd_config
Permissions, ownership and sudo
Every file has an owner, a group and permissions for owner, group and everyone else. ls -l shows them:
-rw-r----- 1 www-data www-data 1820 Nov 24 09:12 wp-config.php
r is read, w is write and x is execute. In numbers, read is 4, write is 2 and execute is 1, so 640 means owner read/write, group read, others nothing.
chmod 640 wp-config.php # set permissions by number
chmod +x backup.sh # make a script executable
sudo chown -R www-data:www-data /var/www/example.com # change owner and group
Tip: If something does not work,
chmod 777is never the fix. It lets every user and every process on the server change the file. Find the user that needs access and give exactly that.
Working as root all the time is risky. Create a normal user and give it admin rights through sudo:
sudo adduser deploy
sudo usermod -aG sudo deploy # Ubuntu and Debian
sudo usermod -aG wheel deploy # AlmaLinux and Rocky Linux
whoami && id # check who you are and which groups you are in
Installing and updating software
Ubuntu and Debian use apt; AlmaLinux and Rocky Linux use dnf.
| Task | Ubuntu / Debian | AlmaLinux / Rocky |
|---|---|---|
| Refresh package lists | sudo apt update | sudo dnf check-update |
| Install updates | sudo apt upgrade | sudo dnf upgrade |
| Install a package | sudo apt install htop | sudo dnf install htop |
| Remove a package | sudo apt remove htop | sudo dnf remove htop |
| Search | apt search nginx | dnf search nginx |
On AlmaLinux and Rocky, some tools such as htop come from the EPEL repository, which you enable with sudo dnf install epel-release. For a safe update routine, see how to update Ubuntu Server safely.
Services and logs
Almost every service on a modern distribution is managed by systemd through systemctl:
systemctl status nginx # is it running? recent log lines
sudo systemctl restart nginx # stop and start
sudo systemctl reload nginx # re-read config without dropping connections
sudo systemctl enable nginx # start at boot
sudo systemctl disable nginx # don't start at boot
systemctl --failed # list services that failed
Logs from those services are read with journalctl:
journalctl -u nginx -n 50 # last 50 lines for one service
journalctl -u ssh -f # follow live (the service is sshd on AlmaLinux/Rocky)
journalctl -p err -b # errors since the last boot
journalctl --since "1 hour ago" # everything from the last hour
Some applications still write plain files in /var/log, which you read with tail or less.
Processes, memory and disk space
top # live view of processes (q to quit); htop is friendlier
free -h # memory; look at the "available" column
uptime # load average for 1, 5 and 15 minutes
ps aux | grep php # find specific processes
kill 12345 # ask process 12345 to stop
df -h # free space per file system
sudo du -sh /var/* | sort -h # which directories use the most space
Load average is easiest to read next to the number of vCPUs (nproc). A load of 2.0 on a 4-vCPU server is fine; 8.0 on the same server means work is queuing. A full disk is one of the most common reasons databases and web servers suddenly stop, so check df -h early. The guide on monitoring CPU, RAM, disk and network goes deeper.
Pipes, redirection and chaining commands
Linux commands are small tools that do one thing, and you combine them. The pipe | sends the output of one command into the next:
journalctl -u nginx | grep -i error | tail -n 20
ps aux --sort=-%mem | head -n 10
Redirection writes output to a file. > overwrites the file and >> appends to it, so double-check which one you type:
df -h > disk-report.txt
echo "checked $(date)" >> disk-report.txt
To run several commands in a row, && only continues if the previous command succeeded, while ; continues regardless:
sudo apt update && sudo apt upgrade
sudo nginx -t && sudo systemctl reload nginx
The second line is a good habit: Nginx is only reloaded if its configuration test passes. Writing files that need root is a common stumbling block, because sudo echo "x" > /etc/file fails: the redirection runs as your user. Use echo "x" | sudo tee /etc/file instead.
Networking basics
ip a # IP addresses on each interface (IPv4 and IPv6)
ip r # routing table and default gateway
sudo ss -tulpn # which ports are listening, and which program owns them
ping -c 4 example.com # is a host reachable?
curl -I https://example.com # fetch only the HTTP headers
dig example.com A +short # look up a DNS record
ss -tulpn is particularly useful before you configure a firewall, because it shows exactly what is exposed. Continue with how to configure a firewall on your Linux VPS once you know which ports you need.
A simple troubleshooting order
When something stops working, go through the same steps every time instead of guessing:
- Reproduce the symptom.
curl -Ithe site or try the connection yourself. - Check the service.
systemctl status <service>. - Read the log.
journalctl -u <service> -n 100. - Check resources.
df -handfree -h. - Check the port.
sudo ss -tulpnto see if anything listens where it should.
Most problems show up by step three.
In short
You need a few dozen commands to run a Linux server well: cd, ls and less to look around, nano to edit, chmod and chown for permissions, apt or dnf for software, systemctl and journalctl for services, and df, free and ss for the state of the machine. Learn the troubleshooting order and you will solve most problems on your own.
Practise on a Hostigan VPS
A Hostigan VPS gives you full root access on KVM with NVMe storage, IPv4 and IPv6, and your choice of Ubuntu, Debian, AlmaLinux or Rocky Linux, so every command in this guide works exactly as shown. Snapshots on VPS Plus and up make it easy to experiment and roll back.
Frequently asked questions
Both install and update packages from the same repositories. apt is the friendlier command meant for people at a terminal, with progress bars and colour, while apt-get has a stable output format that suits scripts.