Essential Linux & SSH Commands for Server Management

Linux SSH commands are typed instructions you send to a remote server after logging in with SSH (Secure Shell), an encrypted connection to the server's command line. You connect with ssh username@server_ip, then use commands like ls, cd, chmod, and systemctl to manage files, permissions, and services.

Key takeaways

  • SSH is the secure, encrypted way to reach your server's terminal from your own computer.
  • The one command to remember for connecting is ssh username@server_ip.
  • Most day-to-day work uses a small set of commands for files, permissions, processes, packages, and services.
  • SSH keys are safer than passwords and are the recommended way to log in.
  • Treat rm -rf and sudo with care, and keep backups before you change anything important.

What SSH is, in plain English

SSH stands for Secure Shell. It is an encrypted way to log into and control a remote server from your own computer's terminal. Instead of clicking buttons in a control panel, you type commands and the server runs them and sends the results back. Because the connection is encrypted, no one on the network in between can read your password or the commands you send.

If you have moved past shared hosting to your own machine, this is how you will do most of your work. A quick primer on that kind of server lives in our guide to what VPS hosting is. A terminal is simply the text window on your computer where you type these commands. On Linux and macOS it is built in; on Windows you can use the built-in Windows Terminal or a small free program called PuTTY.

Nothing you read here can hurt your local computer. The commands below run on the server you connect to, so the risk is limited to that server, and most of these commands only read information rather than change it.

How to connect to your server with SSH

You only need four steps to reach the command line of your server. Have your username and server IP address (a set of numbers like 203.0.113.10) ready before you start; your host shows both in your account dashboard.

  1. Open your terminal. On Linux or macOS, open the Terminal app. On Windows, open Windows Terminal, or install an SSH client such as PuTTY if you prefer a graphical login window.
  2. Start the connection. Type ssh username@server_ip and press Enter. For example: ssh root@203.0.113.10. Replace username with your login name and server_ip with your server's address.
  3. Authenticate. Prove who you are with your password or, more securely, an SSH key. The first time you connect you may see a prompt asking you to confirm the server's fingerprint; type yes to continue.
  4. You're in. You now see the server's command prompt (often ending in $ or #). Every command you type from here runs on the server. Type exit when you want to log out.

SSH keys vs passwords. A password is something you type each time, and a weak one can be guessed by automated attacks. An SSH key is a pair of long, matched files: a public key you place on the server and a private key that stays on your computer. When they match, you are let in without typing a password. Keys are far harder to guess and are the recommended method. You generate a key pair with ssh-keygen and copy the public half to the server with ssh-copy-id username@server_ip.

Navigation and files

These are the commands you will use most. They let you move around the server, look at files, and create, copy, move, or remove them. Think of the server as a set of folders (called directories) you walk through by name.

CommandWhat it doesExample
pwdPrints the working directory: shows where you are right now.pwd
lsLists the files and folders in the current directory.ls
ls -laLists everything, including hidden files, with permissions, owner, size, and date.ls -la /var/www
cdChanges directory: moves you into another folder.cd /var/www/html
mkdirMakes a new, empty directory.mkdir backups
rmRemoves (deletes) a file. There is no recycle bin.rm old.log
rm -rRemoves a directory and everything inside it. Use with care.rm -r old-site/
cpCopies a file or folder to a new location.cp config.php config.php.bak
mvMoves or renames a file or folder.mv draft.html index.html
touchCreates a new empty file, or updates a file's timestamp.touch index.html
catPrints a file's whole contents to the screen.cat notes.txt
lessOpens a long file one screen at a time. Press q to quit.less access.log
tail -fShows the end of a file and keeps following new lines as they arrive. Great for live logs.tail -f error.log
nanoOpens a simple, friendly text editor. Save with Ctrl+O, exit with Ctrl+X.nano config.php

Permissions and ownership

Every file on a Linux server has permissions (who may read, write, or run it) and an owner. Getting these right is often the fix for "permission denied" errors on a website.

CommandWhat it doesExample
chmodChanges a file's permissions using a three-digit code. 644 is typical for files (owner can edit, others can read); 755 is typical for folders and scripts (owner can edit, others can read and enter).chmod 644 index.php
chownChanges who owns a file or folder. Add -R to apply it to everything inside.chown -R www-data:www-data /var/www/html
sudoRuns a single command with administrator rights. You put it in front of a command that needs elevated access.sudo systemctl restart nginx

Searching for files and text

When you cannot remember where a file is, or you need to find a line inside many files, these two commands do the work for you.

CommandWhat it doesExample
findSearches for files and folders by name, type, size, or age, starting from a folder you name.find /var/www -name "*.php"
grepSearches inside files for a word or phrase. Add -r to search a whole folder.grep -r "database_name" /var/www

System and processes

These commands tell you how healthy the server is: what is running, how busy it is, and whether it is running low on memory or disk space. They are the first place to look when a site feels slow.

CommandWhat it doesExample
topShows live running programs and how much processor and memory each one uses. Press q to quit.top
htopA friendlier, colourful version of top. You may need to install it first.htop
ps auxLists every process running right now, with its owner and ID.ps aux | grep nginx
killStops a stuck process by its ID number (shown by ps or top).kill 4821
df -hShows how much disk space is used and free, in easy-to-read sizes.df -h
free -mShows how much memory (RAM) is used and free, in megabytes.free -m
uptimeShows how long the server has been running and how busy it has been.uptime
whoamiPrints the username you are currently logged in as.whoami

Installing and updating software (Debian/Ubuntu)

On Debian and Ubuntu servers, apt is the tool that installs and updates software from trusted sources. Run these with sudo because they change the whole system. (On other systems such as CentOS or AlmaLinux the equivalent tool is dnf or yum.)

CommandWhat it doesExample
apt updateRefreshes the list of available software and versions. It does not change anything yet.sudo apt update
apt upgradeInstalls the newer versions found by apt update.sudo apt upgrade
apt installInstalls a named program and anything it needs to run.sudo apt install htop

Networking and connection checks

When something cannot be reached, these commands help you tell whether the problem is the network, a domain name, or a program that is not listening. Domain names are covered in more depth on our VPS hosting guide.

CommandWhat it doesExample
pingChecks whether another machine answers, and how fast. Press Ctrl+C to stop.ping google.com
curlFetches a web address from the command line, useful for testing a site or an API.curl -I https://example.com
wgetDownloads a file from a web address and saves it to disk.wget https://example.com/file.zip
ssShows which network ports are open and which programs are listening.ss -tulpn
netstatAn older tool that does much the same as ss; still common on many servers.netstat -tulpn
digLooks up a domain's DNS records so you can confirm where a name points.dig example.com
nslookupA simpler DNS lookup tool for checking the IP behind a domain.nslookup example.com

Archives, backups, and transferring files

These commands bundle files together, shrink them, and move them between your computer and the server. They are the backbone of backups and deployments.

CommandWhat it doesExample
tarBundles many files into one archive (a .tar file). Add z to also compress it.tar -czf site.tar.gz /var/www/html
gzipCompresses a single file to save space.gzip access.log
unzipExtracts the contents of a .zip file.unzip theme.zip
scpSecurely copies a file between your computer and the server over SSH.scp backup.tar.gz root@203.0.113.10:/root/
rsyncCopies and syncs folders, transferring only what changed. Ideal for repeat backups.rsync -av /var/www/ /backup/www/

Managing services and reading logs

A service is a program that runs in the background, such as your web server or database. systemctl starts and stops them, and journalctl shows you their logs when something goes wrong.

CommandWhat it doesExample
systemctl statusShows whether a service is running, and its recent activity.systemctl status nginx
systemctl startStarts a stopped service.sudo systemctl start nginx
systemctl stopStops a running service.sudo systemctl stop nginx
systemctl restartStops and starts a service, often needed after a config change.sudo systemctl restart nginx
journalctlReads the system and service logs. Add -u to focus on one service.journalctl -u nginx

Safety tips before you type

The command line is powerful because it does exactly what you tell it, at once, with no confirmation. A few habits keep you out of trouble.

Be extremely careful with rm -rf. This deletes a folder and everything inside it, permanently, with no recycle bin and no undo. Read the path twice before you press Enter, and never run it against / or a path you are unsure of.

Use sudo deliberately. It gives a command full control of the server. Run only commands you understand with it, and never paste a sudo command from a source you do not trust.

Keep backups. Before you edit a config file or delete anything, make a copy first, for example cp config.php config.php.bak. A snapshot from your host is even better.

Double-check before deleting or overwriting. Confirm you are in the right directory with pwd, and list the files with ls, before you remove or move them.

Frequently asked questions

What is SSH?

SSH stands for Secure Shell. It is an encrypted way to log into and control a remote server from your own computer's terminal. Because the connection is encrypted, your password and commands cannot be read by anyone else on the network. It is the standard way system administrators manage Linux servers.

How do I connect to my server with SSH?

Open your terminal (or an SSH client such as PuTTY on Windows), then type ssh username@server_ip and press Enter, for example ssh root@203.0.113.10. Authenticate with your password or an SSH key. You will then see the server's command prompt, where every command you type runs on the server.

What's the difference between an SSH key and a password?

A password is text you type each time, and a weak one can be guessed by automated attacks. An SSH key is a matched pair of files: a public key stored on the server and a private key kept on your computer. When they match, you are let in without typing a password. Keys are much harder to break, so they are the recommended login method.

What are the most important Linux commands to learn first?

Start with the ones you use constantly: ls, cd, and pwd to move around; cat, less, and nano to read and edit files; cp, mv, and rm to manage them; and systemctl to control services. These cover most everyday server work.

Is the command line safe for beginners?

Yes, as long as you go slowly and think before you press Enter. Most commands, such as ls, pwd, and df -h, only read information and change nothing. The commands that can cause harm are the deleting and overwriting ones, so double-check the path with those and keep a backup.

Do these commands work on every Linux server?

The file, permission, process, and networking commands here work on almost every Linux system. The package commands (apt) are specific to Debian and Ubuntu; on CentOS, AlmaLinux, or Rocky Linux you would use dnf or yum instead. The service commands (systemctl) work on any modern system that uses systemd, which is most of them.

How do I log out of an SSH session?

Type exit and press Enter, or use the shortcut Ctrl+D. This closes your session and returns you to your own computer's terminal. Your server keeps running everything you started in the background, so logging out does not stop your website.

Summary

SSH gives you a secure, encrypted line to your server's command line, and a small set of Linux commands covers nearly everything you will do there: moving through files, setting permissions, checking system health, installing software, and managing services. Learn the connect step and a dozen everyday commands, keep backups, and treat rm -rf and sudo with respect, and you can run a server with confidence. Ready to put this into practice on your own machine? Follow our step-by-step walkthrough on how to set up a VPS, or browse more guides in the Hosting Help Center.

References

  • OpenSSH project — official manual pages for ssh, ssh-keygen, and scp (openssh.com/manual.html).
  • Debian and Ubuntu documentation — apt package management (help.ubuntu.com).
  • The Linux man-pages project — reference for ls, chmod, find, grep, and rsync (man7.org/linux/man-pages).
  • systemd documentation — systemctl and journalctl (freedesktop.org/wiki/Software/systemd).
Bitrich777 Hosting Team
About the author

The editorial team behind the Bitrich777 Hosting Help Center — practical, tested guides on web hosting, WordPress, servers, DNS, SSL, email, security and migration. Every walkthrough is reproduced on a live host before it is published.

Spotted an error? Tell us