When beginners get their first VPS and SSH into it for the first time, many feel the same way: a black screen, a blinking cursor, and no idea what to do next. The good news is that Linux commands arenโt as scary as they look. For day-to-day VPS management, you only need about 30โ40 commands regularly. Everything else you can look up when you need it.
SSH Connection
The most basic way to connect:
ssh root@your-server-ip
The first time you connect, youโll see a fingerprint confirmation prompt. Just type yes and press Enter. After that, it wonโt ask again for this server.
If your provider uses a non-standard port (or youโve already changed the SSH port โ which I strongly recommend), add the -p flag:
ssh -p 2222 root@your-server-ip
Using SSH key authentication is much more secure than passwords. The private key stays on your local machine, and only the public key lives on the server โ making brute-force attacks almost useless.
# Generate a key pair on your local machine
ssh-keygen -t ed25519
# Copy the public key to the server
ssh-copy-id -p 2222 root@your-server-ip
# Connect using the key
ssh -i ~/.ssh/id_ed25519 -p 2222 root@your-server-ip
Once key login is working, I recommend editing /etc/ssh/sshd_config and setting PasswordAuthentication no to completely disable password login.
File and Directory Operations
These commands are used almost every day:
ls # List files in current directory
ls -lh # List with human-readable sizes and details
cd /var/www # Go to a specific directory
cd .. # Go up one level
cd ~ # Go back to your home directory
pwd # Show current path
Creating and deleting:
mkdir myapp # Create a directory
mkdir -p a/b/c # Create nested directories
touch config.env # Create an empty file
rm file.txt # Delete a file
rm -rf folder/ # Delete a folder and everything inside (irreversible โ use with extreme caution)
rm -rf is the command that trips up most beginners. Always double-check the path before running it, especially if it contains variables. One wrong move and you could accidentally delete your entire system.
Copying and moving:
cp file.txt backup.txt # Copy a file
cp -r folder/ backup_folder/ # Copy an entire directory
mv file.txt /home/user/ # Move a file
mv oldname.txt newname.txt # Rename a file
Viewing file contents:
cat config.txt # Display the entire file
less config.txt # View with paging (press q to quit)
tail -f /var/log/nginx/error.log # Follow log file in real time
grep "error" app.log # Search for a keyword in a file
tail -f is one of the most useful commands when troubleshooting. Open one terminal to watch the logs live while you make changes in another โ youโll immediately see exactly where things go wrong.
Permissions
Use ls -l to check file permissions:
ls -l /var/www/html
# Example output:
# -rw-r--r-- 1 www-data www-data 1234 index.html
The string -rw-r--r-- shows permissions for owner, group, and others. Each group uses r (read=4), w (write=2), x (execute=1).
Change permissions with chmod:
chmod 755 deploy.sh # Owner can read/write/execute, others can read/execute
chmod 644 config.txt # Owner can read/write, others can only read
chmod -R 755 /var/www # Apply recursively to a whole directory
Quick reference: Use 755 for scripts and directories, 644 for normal files, and 600 for private keys.
Change ownership with chown:
chown www-data:www-data /var/www/html
chown -R www-data:www-data /var/www # Recursive
Nginx and Apache usually run as the www-data user. If website files donโt belong to the correct user, youโll get 403 Forbidden errors โ one of the most common pitfalls when new users deploy WordPress.
Process and System Management
Monitor system resources:
top # Real-time CPU and memory (press q to quit)
htop # Nicer version (install with: apt install htop)
ps aux # List all running processes
ps aux | grep nginx # Find a specific process
Kill processes:
kill 1234 # Graceful termination
kill -9 1234 # Force kill immediately
pkill nginx # Kill by process name
Check which ports are in use (useful when you see โport already in useโ errors):
ss -tulpn
# or
netstat -tulpn # requires net-tools package
Check disk and memory usage:
df -h # Disk usage
du -sh /var/www # Size of a specific directory
free -h # Memory usage
Software Installation (Ubuntu/Debian)
apt update # Refresh package list
apt upgrade -y # Upgrade all installed packages
apt install nginx -y # Install a package
apt remove nginx # Remove a package
apt autoremove # Clean up unused packages
Search for packages:
apt search nginx
Service Management (systemd)
Modern Linux uses systemd to manage services:
systemctl start nginx # Start
systemctl stop nginx # Stop
systemctl restart nginx # Restart
systemctl reload nginx # Reload config without dropping connections
systemctl enable nginx # Enable auto-start on boot
systemctl disable nginx # Disable auto-start
systemctl status nginx # Check service status
systemctl status is usually the first command you run when something isnโt working โ it shows whether the service is running, recent log output, and exit codes.
View detailed logs:
journalctl -u nginx # Full logs for a service
journalctl -u nginx -f # Follow logs in real time
journalctl -u nginx --since "1 hour ago" # Logs from the last hour
Network Troubleshooting
ping google.com # Test connectivity (Ctrl+C to stop)
curl -I https://example.com # Show HTTP response headers
wget https://example.com/file.tar.gz # Download a file
ip a # Show network interfaces and IP addresses
Trace routes (helpful for diagnosing network issues):
traceroute google.com
mtr google.com # Better real-time version
Productivity Tips
Press Tab to auto-complete commands and paths โ this habit saves a huge amount of time and prevents typos.
Use the up/down arrow keys to browse command history. Type history to see all previous commands, or !1234 to re-run command number 1234.
Keyboard shortcuts:
Ctrl + Cโ interrupt the current commandCtrl + Zโ suspend the current command to backgroundfgโ bring the suspended command back to foreground
Use the pipe | to combine commands:
# Show top 5 processes by memory usage
ps aux --sort=-%mem | head -5
# Live filter logs for errors
tail -f /var/log/nginx/error.log | grep "error"
# Count files in a directory
ls /var/www | wc -l
Quick Command Cheat Sheet
| Task | Command |
|---|---|
| Connect to server | ssh root@IP |
| List directory contents | ls -lh |
| Change directory | cd /path |
| Delete file/folder | rm file or rm -rf folder |
| Change permissions | chmod 755 file |
| Change owner | chown user:user file |
| Monitor resources | htop or top |
| Check open ports | ss -tulpn |
| Check disk usage | df -h |
| Install software | apt install xxx -y |
| Manage services | systemctl start/stop/status |
| Follow logs live | tail -f logfile |
You donโt need to memorize everything at once. Look up the command when you need it, and after using it a few times it will stick naturally. The real skill isnโt remembering every flag โ itโs knowing which command to reach for when you run into a problem.