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.
- Start PuTTY.
- In the
Host Name (or IP address)field, enter your server's IP address. - The port should be
22. - Click
Open. - 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_addressUpdate 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 -yBasic 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 lsThis 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.
Navigate and manage files
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 -laSample 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,dfor a directory). The next 9 characters are the permissions for the owner, the group and others, in that order.1or2: 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.htmlCopy 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
lsDelete 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_siteView file contents
Say you want to check the Nginx logs to track down a problem.
cat /var/prints the whole log file. If the file is large, it floods your terminal.log/ nginx/ access.log less /var/opens the file inlog/ nginx/ error.log less, where you can scroll with the arrow keys. Pressqto quit.tail /var/shows the last 10 lines of the log, handy for a quick look at the newest entries.log/ nginx/ access.log tail -f /var/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. Presslog/ nginx/ access.log Ctrl + Cto stop.
Manage processes
Say one process is using 100% of the CPU and you need to stop it.
- Run
htop(ortop) to see the processes sorted by resource usage. - Find the process causing trouble and note its
PID(process ID). - Press
qto leavehtop. - 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 1234You 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 nodeManage 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 adminOn Fedora/Rocky the process is similar, but the group is wheel:
sudo useradd admin
sudo passwd admin
sudo usermod -aG wheel adminChange 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 adminAfter 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 adminEdit 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.cfgThe 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 -hshows disk usage for every mounted partition in a readable format (megabytes, gigabytes).free -hshows 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 nginxchecks whether Nginx is running.sudo systemctl start nginxstarts the service.sudo systemctl stop nginxstops the service.sudo systemctl restart nginxrestarts the service (for example after a configuration change).sudo systemctl enable nginxstarts the service automatically at boot. With--now(sudo systemctl enable --now nginx) it also starts right away.sudo systemctl disable nginxturns 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).
chmodchanges permissions.chownchanges 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.shTo change a file's owner:
# Make user "admin" and group "admin" the owner of the file
sudo chown admin:admin start.shNumeric 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) = 4w(write) = 2x(execute) = 1
To set the permissions for one class (for example the owner), add up the values:
0(---): no permissions1(--x): execute only2(-w-): write only3(-wx): write and execute4(r--): read only5(r-x): read and execute6(rw-): read and write7(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