Essential Linux Commands for VPS and Dedicated Server Management

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.