Skip to Content

Server basics

An introduction to managing a Linux server.

Connect to the server over SSH

SSH (Secure Shell) is a protocol for logging in to and managing a server remotely and securely.

What you need

  • Server IP address: 93.95.119.x (use your server's address)
  • Username: usually root, or the user you set when you ordered the server
  • Password: that user's password

The most popular SSH client for Windows is PuTTY. You can download it from putty.org.

  1. Start PuTTY.
  2. In the Host Name (or IP address) field, enter your server's IP address.
  3. The port should be 22.
  4. Click Open.
  5. In the new window, enter your username and then your password.

Recent versions of Windows 10 and 11 also include an OpenSSH client. You can use it in PowerShell or CMD:

ssh username@server_ip_address

Update the system

Regular updates are key to your server's security and stability.

Packages are managed with apt.

# Refresh the list of available packages
sudo apt update

# Upgrade the installed packages to their latest versions
sudo apt upgrade -y

Basic commands for getting around

Below are the essential commands, with practical examples of how to use them in everyday work.

man: the full system manual

The man (manual) command opens the full Linux documentation. It is one of the most important tools for any Linux user or administrator. It tells you how each command works, which options it has and how to use it.

To use man, run:

man [command_name]

For example:

man ls

This opens the manual page for ls, with details on how it works, its options and usage examples. Press q to leave the manual.

You can search the manual: press /, type a word and press Enter.

Say you want to create a directory for your new website, put a file in it and then move the file.

Check where you are and what is there

# Print the current directory
pwd
# Output: /home/username

ls -la

Sample ls -la output

-rw-r--r-- 1 admin admin 1234 Mar 23 15:01 config.txt
drwxr-xr-x 2 admin admin 4096 Mar 23 15:02 public_html/
  • drwxr-xr-x: the permissions. The first character is the type (- for a file, d for a directory). The next 9 characters are the permissions for the owner, the group and others, in that order.
  • 1 or 2: the number of hard links.
  • admin: the file's owner.
  • admin: the group the file belongs to.
  • 1234: the file size in bytes.
  • Mar 23 15:01: the last modification date.
  • config.txt: the file or directory name.

Create a directory and files

# Create a directory for the project
mkdir my_site

# Go into the new directory
cd my_site

# Create an empty HTML file
touch index.html

Copy and move files

# Copy index.html to contact.html
cp index.html contact.html

# Rename contact.html to contact-us.html
mv contact.html contact-us.html

# Move contact-us.html to the parent directory
mv contact-us.html ../

# List the directory to see the changes
ls

Delete files and directories

Careful! rm deletes files and directories permanently. There is no recycle bin. Use it with care.

# Delete contact-us.html
rm contact-us.html

# Delete a write-protected file without asking for confirmation
rm -f protected_file.txt

# Go back to the parent directory
cd ..

# Delete the my_site directory and everything in it
rm -r my_site

View file contents

Say you want to check the Nginx logs to track down a problem.

  • cat /var/log/nginx/access.log prints the whole log file. If the file is large, it floods your terminal.
  • less /var/log/nginx/error.log opens the file in less, where you can scroll with the arrow keys. Press q to quit.
  • tail /var/log/nginx/access.log shows the last 10 lines of the log, handy for a quick look at the newest entries.
  • tail -f /var/log/nginx/access.log is one of the most useful diagnostic tools. It prints new lines as they are added to the file, so you can watch what happens on the server in real time. Press Ctrl + C to stop.

Manage processes

Say one process is using 100% of the CPU and you need to stop it.

  1. Run htop (or top) to see the processes sorted by resource usage.
  2. Find the process causing trouble and note its PID (process ID).
  3. Press q to leave htop.
  4. Stop the process with kill.
# Stop the process gracefully (1234 is the process PID)
kill 1234

# If that doesn't work, force it to stop
kill -9 1234

You can also use killall to stop every process with a given name. This helps when an application has started many processes.

# Stop every process named "node"
sudo killall node

Manage users

It is good practice to create a new user with sudo rights instead of working as root.

# Create a new user named "admin" (on Debian/Ubuntu)
sudo adduser admin

# Add "admin" to the sudo group so it can run commands with elevated privileges
sudo usermod -aG sudo admin

# Switch to the new account
su admin

On Fedora/Rocky the process is similar, but the group is wheel:

sudo useradd admin
sudo passwd admin
sudo usermod -aG wheel admin

Change a user's password

The passwd command changes a user's password. You can change your own password or, as an administrator, another user's.

# Change your own password
passwd

# Change the password of "admin" (needs sudo)
sudo passwd admin

After the change, the user logs in with the new password. To make a user change their password at the next login, run:

sudo passwd -e admin

Edit files in the terminal

Sooner or later you will need to edit a configuration file. The simplest editor for beginners is nano. Say you want to edit server.cfg in /home/admin/fivem:

nano /home/admin/fivem/server.cfg

The nano editor opens. The keyboard shortcuts are listed at the bottom of the screen:

  • Ctrl + O: save the changes (Write Out).
  • Ctrl + X: exit the editor.

There is also Vim (and its fork Neovim), a much more powerful editor that is harder to learn.

Monitor system resources

Checking free disk space and available RAM are basic admin tasks.

  • df -h shows disk usage for every mounted partition in a readable format (megabytes, gigabytes).
  • free -h shows used and free RAM and swap.
  • du -sh * shows which directories in the current location take up the most space.

Manage services (systemd)

Most modern Linux distributions use systemd to manage services (daemons) such as a web server, a database or the firewall. Say you have installed the Nginx web server.

  • sudo systemctl status nginx checks whether Nginx is running.
  • sudo systemctl start nginx starts the service.
  • sudo systemctl stop nginx stops the service.
  • sudo systemctl restart nginx restarts the service (for example after a configuration change).
  • sudo systemctl enable nginx starts the service automatically at boot. With --now (sudo systemctl enable --now nginx) it also starts right away.
  • sudo systemctl disable nginx turns off the automatic start.

File permission basics

Every file and directory in Linux has permissions for three classes of users:

  • owner (user)
  • group (group)
  • others (others)

The permissions are r (read), w (write) and x (execute).

  • chmod changes permissions.
  • chown changes the owner and group.

For example, you have a start.sh script that you need to make executable.

# Give the file's owner execute permission (+x)
chmod u+x start.sh

# Now you can run it
./start.sh

To change a file's owner:

# Make user "admin" and group "admin" the owner of the file
sudo chown admin:admin start.sh

Numeric permissions in chmod

You can also set permissions with numbers (octal notation), which is faster and very common. Each permission has a value:

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1

To set the permissions for one class (for example the owner), add up the values:

  • 0 (---): no permissions
  • 1 (--x): execute only
  • 2 (-w-): write only
  • 3 (-wx): write and execute
  • 4 (r--): read only
  • 5 (r-x): read and execute
  • 6 (rw-): read and write
  • 7 (rwx): full permissions (read, write, execute)

chmod takes a three-digit number: the first digit is for the owner, the second for the group and the third for others.

Practical examples

  • chmod 755 file.sh: the most common permissions for scripts and public directories. Owner 7 (rwx), group 5 (r-x), others 5 (r-x).
  • chmod 644 config.php: typical permissions for website files. Owner 6 (rw-), group 4 (r--), others 4 (r--).
  • chmod 700 private_key: permissions for private keys. Owner 7 (rwx), group 0 (---), others 0 (---).

Firewall

ufw (Uncomplicated Firewall) is an easy-to-use firewall tool.

# Allow SSH traffic (very important!)
sudo ufw allow ssh

# Turn on ufw
sudo ufw enable

# Allow HTTP and HTTPS traffic
sudo ufw allow http
sudo ufw allow https
sudo ufw allow 8080/tcp

# Check the status
sudo ufw status