Essential Linux Commands for VPS and Dedicated Server Management

Essential Linux Commands

Managing a VPS or dedicated server often requires working directly in Linux, and a fundamental knowledge of Linux commands is essential for efficient server management. Whether you’re troubleshooting issues, optimizing performance, or maintaining security, the right Linux commands can make your tasks much easier and faster. Here’s a breakdown of essential Linux commands to help you get started.


Essential Linux Commands

1. Basic Navigation and File Management Commands

  • ls
    Lists files and directories in the current directory. Useful options include:
    • ls -a (lists all files, including hidden)
    • ls -l (displays in detailed list format)
  • cd [directory]
    Changes the directory. Example: cd /var/www moves to the /var/www directory.
  • pwd
    Displays the present working directory.
  • cp [source] [destination]
    Copies files or directories. Adding -r copies directories recursively (e.g., cp -r /source /destination).
  • mv [source] [destination]
    Moves or renames files or directories.
  • rm [file]
    Deletes files or directories. Use rm -r with caution, as it removes directories recursively.

2. User and Permission Management Commands

  • adduser [username]
    Adds a new user to the system. Useful when creating separate accounts for better access control.
  • passwd [username]
    Changes the password for a user. Regular password changes help in keeping accounts secure.
  • chmod [permissions] [file]
    Modifies file permissions. For example, chmod 755 filename sets read, write, and execute permissions for the owner, and read and execute for others.
  • chown [user]:[group] [file]
    Changes the file ownership. Example: chown user:group filename.

3. System Monitoring and Resource Management Commands

  • top
    Provides a dynamic view of system processes, showing CPU and memory usage. Ideal for identifying resource-hogging processes.
  • htop
    Similar to top but with a more user-friendly interface. Use apt-get install htop or yum install htop to install.
  • df -h
    Displays disk space usage in human-readable format. Useful for monitoring available storage.
  • du -sh [directory]
    Shows the size of a directory. The -h option makes the output human-readable.
  • free -m
    Displays memory usage. The -m flag shows output in megabytes, making it easier to understand.

4. Network and Connection Commands

  • ping [hostname/IP]
    Checks connectivity to another server or website, ideal for troubleshooting connection issues.
  • ifconfig
    Displays IP and network configuration details. Use ip addr on newer systems as ifconfig may be deprecated.
  • netstat -tuln
    Shows active connections and listening ports. Useful for security and network diagnostics.
  • traceroute [hostname/IP]
    Tracks the path packets take to reach their destination, helping identify network bottlenecks.

5. Process Management Commands

  • ps aux
    Lists all running processes along with details like CPU and memory usage.
  • kill [PID]
    Terminates a process by its Process ID (PID). You can find the PID using ps aux or top.
  • killall [process name]
    Kills all instances of a specific process.

6. Security and Firewall Commands

  • ufw
    (Uncomplicated Firewall) is a front-end for iptables and is easier for basic configurations.
    • ufw enable – Enables the firewall.
    • ufw allow [port] – Allows incoming connections on a specific port.
    • ufw deny [port] – Blocks incoming connections on a specific port.
  • iptables
    Advanced firewall management for those needing specific rule sets.
    • Example: iptables -A INPUT -p tcp --dport 22 -j ACCEPT allows SSH access.

7. File Editing Commands

  • nano [filename]
    Opens a simple text editor, ideal for quick edits.
  • vi [filename]
    Opens the vi editor, commonly used on Linux servers. It has a steeper learning curve but offers powerful editing capabilities.

8. Backup and Restore Commands

  • tar -czvf [archive-name].tar.gz [directory]
    Creates a compressed archive of a directory.
  • rsync -avz [source] [destination]
    Syncs files between directories or even across servers. It’s efficient and preserves permissions.

Conclusion

These essential Linux commands provide a solid foundation for managing your VPS or dedicated server effectively. Mastering them can make daily tasks faster and easier, from routine monitoring to ensuring server security. Whether you’re a beginner or brushing up on skills, these commands cover the fundamentals needed for smooth, efficient server management.

How to Access Your Server via SSH

access server via ssh

Secure Shell (SSH) is a popular protocol for accessing and managing remote servers securely. With SSH, you can control your server from anywhere and handle basic maintenance, updates, and configurations.

access server via ssh

Step 1: Get the Necessary Details

To access your server via SSH, you need:

  • Server IP address – This is the unique identifier of your server.
  • Username – Usually provided by your hosting provider when setting up your server.
  • Password or SSH Key – Your login credential for secure access.

Step 2: Install an SSH Client

If you’re on Linux or macOS, you already have a built-in Terminal app that supports SSH. Windows users can use PuTTY, a reliable and free SSH client.

Step 3: Connect to Your Server

  1. Open your SSH client: Launch Terminal on Linux/macOS or PuTTY on Windows.
  2. Enter the connection command: In the Terminal, type the following command:
    codessh username@server_ip
    Replace username with your actual username and server_ip with your server’s IP address.
  3. Authenticate: You’ll be prompted to enter your password. If using an SSH key, ensure it’s correctly configured.

Step 4: Start Managing Your Server

Once connected, you’ll see a prompt indicating you’re logged in. You can now start managing your server, perform updates, configure settings, or check performance stats.

Quick Tips for Secure SSH Access

  • Change the default SSH port: Many users change the SSH port from 22 to something unique to reduce unauthorized access attempts.
  • Enable SSH key authentication: SSH keys are more secure than password-only access.
  • Regularly update your SSH client: Keeping your SSH client up to date is essential for security.