cPanel's web interface handles most day-to-day hosting tasks well. But there are jobs where clicking through a browser interface is slow and inefficient — bulk file operations, debugging permission errors, searching through logs, managing processes, or running scripts directly. SSH (Secure Shell) is the answer to all of these.

SSH gives you a direct terminal session on your hosting server. You type commands, the server executes them, and results appear immediately. It sounds intimidating if you've never used it, but the set of commands you'll reach for regularly is small and learnable.

This guide covers the commands that actually come up in a hosting context — not an exhaustive Linux reference, but the ones that solve real problems.


Connecting via SSH

Enabling SSH Access in cPanel

SSH access may need to be enabled on your account before you can connect. If you don't have root access or Reseller WHM access, consult your host provider to enable it. Some hosts require SSH keys and its good practice to use them for security reasons even if its not enforced. Go to cPanel > Security > SSH to enable/upload SSH keys.

Connecting From Your Computer

On Mac or Linux, open Terminal and run:

ssh username@yourdomain.com

Replace username with your cPanel username and yourdomain.com with your domain or server hostname. You'll be prompted for your cPanel password.

On Windows, use PuTTY (free, putty.org) or the built-in SSH client in Windows Terminal or WSL:

ssh username@yourdomain.com

When you connect for the first time, SSH will ask you to confirm the server's fingerprint. Type yes and press Enter. You'll only need to do this once.

After connecting, you'll see a command prompt that looks something like:

[username@server ~]$

The ~ means you're currently in your home directory. Commands you type here run on the server.


Navigating the Filesystem

pwd — Print Working Directory

Shows your current location in the filesystem:

pwd

Output: /home/yourusername

ls — List Files and Directories

ls

Lists files in the current directory. Useful flags:

ls -l        # Long format: shows permissions, owner, size, date
ls -la       # Long format including hidden files (files starting with .)
ls -lh       # Long format with human-readable file sizes (KB, MB, GB)
ls -lt       # Sort by modification time, newest first

In a hosting context, ls -lah in your public_html directory is one of the most frequently used commands — it shows you everything including hidden files like .htaccess, with readable sizes and timestamps.

cd — Change Directory

cd public_html              # Move into public_html
cd wp-content/themes        # Move into a subdirectory
cd ..                       # Move up one directory level
cd ~                        # Return to your home directory
cd /home/yourusername/logs  # Move using an absolute path

Common Directory Paths in cPanel

/home/yourusername/           Your home directory
/home/yourusername/public_html/    Your main website root
/home/yourusername/logs/           Apache access and error logs
/home/yourusername/etc/           Mail and account config files
/tmp/                             Temporary files

Working With Files

cat — Display File Contents

cat wp-config.php           # Print entire file to terminal
cat .htaccess               # View your htaccess file

For long files, pipe through less for paginated viewing:

cat error_log | less        # Scroll through with spacebar, quit with q

less — Browse a File With Scroll Control

less /home/yourusername/logs/yourdomain.com-ssl_log

Navigate with arrow keys or spacebar. Press / followed by a search term to search within the file. Press q to quit.

tail — Show the End of a File

Particularly useful for watching log files in real time:

tail error_log              # Show last 10 lines
tail -n 50 error_log        # Show last 50 lines
tail -f error_log           # Follow the file in real time (Ctrl+C to stop)

tail -f on your PHP error log or Apache error log while you reproduce a bug is one of the most practical debugging techniques in a hosting environment.

grep — Search File Contents

grep "Fatal error" error_log              # Find all fatal errors in the log
grep -i "out of memory" error_log         # Case-insensitive search
grep -r "wp_options" /home/user/public_html/  # Recursive search in directory
grep -n "database" wp-config.php          # Show line numbers with matches

To find which PHP file contains a specific string across your entire site:

grep -r "base64_decode" /home/yourusername/public_html/

This is a useful malware-hunting command — base64_decode in PHP files is a common sign of injected malicious code.

find — Locate Files by Name, Date, or Permissions

Find all PHP files modified in the last 24 hours (useful after a hack):

find /home/yourusername/public_html/ -name "*.php" -mtime -1

Find all files with permissions set to 777:

find /home/yourusername/public_html/ -perm 777

Find files larger than 100MB:

find /home/yourusername/ -size +100M

cp, mv, rm — Copy, Move, Delete

cp file.php file-backup.php             # Copy a file
cp -r wp-content/ wp-content-backup/   # Copy a directory recursively
mv oldname.php newname.php             # Rename or move a file
mv file.php /home/user/backups/        # Move to another directory
rm unwanted-file.php                   # Delete a file
rm -rf old-plugin-folder/             # Delete a directory and all contents

Be careful with rm -rf — it deletes immediately with no confirmation and no recycle bin. Double-check the path before running it while the rm command itself will ask for confirmation, it still permanently deletes the file.

nano — Edit a File in the Terminal

nano wp-config.php
nano .htaccess

Nano is a simple terminal text editor. Edit with normal typing, save with Ctrl+O then Enter, exit with Ctrl+X. For quick edits to config files when you don't want to open File Manager, nano is the fastest option. While nano is widely available on most installations, it may not be available on your current service. If you have root or sudo access you can install it, otherwise you're limited to what is made available on your system which could be vim or vi for example.


File Permissions

Permissions in Linux control who can read, write, and execute a file. In a hosting context, wrong permissions are a common cause of errors and a common security vulnerability.

chmod — Change File Permissions

Standard secure permissions for web hosting:

chmod 644 filename.php      # Files: owner read/write, group/others read only
chmod 755 directory-name/   # Directories: owner full, group/others read+execute
chmod 600 wp-config.php     # Config files with credentials: owner read/write only

To set permissions recursively across all files and directories:

find /home/yourusername/public_html/ -type f -exec chmod 644 {} \;
find /home/yourusername/public_html/ -type d -exec chmod 755 {} \;

Never set files or directories to 777 (read/write/execute for everyone). It's a serious security risk in a shared hosting environment.

chown — Change File Ownership

On shared hosting you typically won't need this, but on a VPS:

chown yourusername:yourusername filename.php
chown -R yourusername:yourusername /home/yourusername/public_html/

Disk Usage

Running out of disk space is a common issue, especially with accumulated backups and log files.

du — Disk Usage of Files and Directories

du -sh /home/yourusername/         # Total size of your home directory
du -sh /home/yourusername/*/       # Size of each subdirectory
du -sh public_html/*               # Size of each item in public_html

Finding what's eating your disk space:

du -sh /home/yourusername/* | sort -rh | head -20

This lists the 20 largest items in your home directory sorted by size, largest first.

df — Disk Free Space on the Server

df -h

Shows all mounted filesystems and how much space is used versus available. On shared hosting, your usage is tracked by cPanel's quota system rather than here, but on a VPS this is how you check overall disk status.


Processes and Performance

top — Live Process Monitor

top

Shows a live view of all running processes sorted by CPU usage. Press M to sort by memory usage instead. Press q to quit.

ps — List Running Processes

ps aux | grep php           # Find all running PHP processes
ps aux | grep yourusername  # Find all processes running as your user

kill — Terminate a Process

kill 12345                  # Gracefully stop process with PID 12345
kill -9 12345               # Force-kill the process immediately

Get the PID from the output of ps or top.


MySQL From the Command Line

Connect to MySQL

mysql -u dbusername -p databasename

You'll be prompted for the database user's password. Once connected, you're in the MySQL shell.

Useful MySQL Commands

SHOW TABLES;                          -- List all tables in the database
SELECT COUNT(*) FROM wp_posts;        -- Count rows in a table
SHOW TABLE STATUS;                    -- Size and row count for all tables
OPTIMIZE TABLE wp_posts;              -- Defragment and optimize a table

Exit the MySQL shell with exit or Ctrl+D.

Export a Database (mysqldump)

mysqldump -u dbusername -p databasename > backup-$(date +%Y%m%d).sql

Import a Database

mysql -u dbusername -p databasename < backup.sql

Useful Compound Commands

Search for a String Across All PHP Files

grep -rl "suspicious_function" /home/yourusername/public_html/

The -r flag is recursive, -l shows only filenames rather than each match.

Count Lines in a Log File

wc -l /home/yourusername/logs/yourdomain.com-ssl_log

Watch a Log File for a Specific Error

tail -f error_log | grep "PHP Fatal"

Streams only lines containing "PHP Fatal" from the live log — useful when debugging a specific error type without noise from everything else.

Clear PHP Error Log

> /home/yourusername/public_html/error_log

The > with nothing before it overwrites the file with empty content, effectively clearing it without deleting it.

Run a WordPress CLI Command (WP-CLI)

If WP-CLI is available on your host (it is on many cPanel servers):

wp --info                               # Confirm WP-CLI is available
wp plugin list                         # List all installed plugins
wp plugin update --all                 # Update all plugins
wp user list                           # List WordPress users
wp search-replace 'http://' 'https://' # Update URLs in database
wp cache flush                         # Clear WordPress object cache

WP-CLI is one of the most powerful tools available for WordPress management from the command line.


SSH Key Authentication (Recommended)

Password-based SSH is convenient but vulnerable to brute force attacks. SSH key authentication is more secure — you generate a key pair on your computer, upload the public key to your hosting account, and SSH connects automatically without a password.

In cPanel, go to Security → SSH Access → Manage SSH Keys to generate or import keys. Follow the on-screen instructions to authorize your public key, and your future SSH connections will use the key pair instead of your password.


Need SSH access enabled on your Lone Star Hosting account, or have questions about using the terminal? Contact our support team and we'll get you set up.