Crucial SSH Commands that Every WordPress User Should Know


Ever wished you could dive deeper into your WordPress site, beyond the familiar dashboard? What if you could troubleshoot issues faster, optimise performance with precision, or even secure your website like a pro? The answer might surprise you: it’s all possible with SSH commands. Even if you’re not a coding whizz, understanding these essential tools can transform how you manage your WordPress site. Let’s unlock the potential of your website together.

What is SSH?

From the Wikipedia page, SSH is described as “Cryptographic network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers”. Simply, rather than using a web browser program, you use a “Terminal” program.

If you’re not sure how to use this, read our knowledgebase article here: How to connect via SSH to a cPanel web hosting account

What does this mean for you as a WordPress user?

It means that you can amend details on your website and hosting without having to open a web browser, login, find the settings, etc… Just skip straight to what you want to achieve. Want to run a database backup? No need for a plugin, just run one quick command!

Essential SSH Commands

  • ls: Listing files and directories. This command will help you to understand the fields that you can work on the server.
  • cd: Changing directories (Moving around). This will help you navigate around the remote WordPress environment.
  • pwd: Printing the current working directory. An essential command to help you understand where you currently are within the directory structure
  • mkdir: Creating a new directory.
  • rm: Removing files. Warning: When removing files, there is no trash; When it’s gone, it’s gone.
  • mv: Moving or renaming file. This command will help you make sure the files are in the right place on your server. TIP: Using .. means “parent directory” so if you are working in your public_html directory you can run the command mv example.txt .. to move that file out of public gaze.
  • scp: Copying files. You can use this command to either place or retrieve files from the remote server.
  • nano or vim: Basic text editing
  • tail: Viewing the end of a file. By default, this will show the last 10 lines from the file, but that can be amended with the “-n” flag, e.g. tail -n 25 example.txt will show the last 25 lines of the txt file
  • head: Viewing the beginning of a file
  • grep: Searching for text within files
  • find: Searching for files and directories

Getting Help

Beyond the above commands, you may need a prompt to help understand how to use the script, or the flag that are available.

For most commands, the manual will be available with the man command or the -h / --help flags.

For example, mv --help outputs:

Terminal showing mv command help options.

WordPress Specific Commands

Within our hosting environment, we have a program available to you called WP-CLI that allows you to amend your WordPress website with a simple, but powerful, set of commands.

You can read more about the WP-CLI project or WP-CLI commands on the WordPress developer site.

Essential WP-CLI Commands

All WP-CLI command start with wp followed by the section of WordPress that you want to interact i.e. plugins and finish with the task you would like to achieve i.e. update

Commands

  • wp db export: This is one of the commands I run the most often, as it ensures you have a full database backup prior to making other changes on your site. This will output a .sql file in the directory you are current working. If you need to move it, you can then use the mv command from above to keep it out of your public_html directory and thus away from access.
  • wp plugin/theme list: To be able to see the current status of the plugins or themes on your site, whether there is an update available and if they are active.
  • wp plugin/theme update: Following on from the previous command, if updates are available, you can run this to pull in the latest code from the WP repository. You will need to add either the plugin slug or use the --all flag at the end
  • wp user create: Need to give access to the site to a new user, you can use this command with the --prompt flag to walk you through the fields needed to get the user up and running.
  • wp media regenerate: Updated some images and need to recreate the thumbnails? Rather than installing a plugin, you can use this command, which twinned with the --only-missing flag means you aren’t overloading your server.

Further Reading:

On our knowledgebase, you can also learn How to change the WordPress Administration Email Address using WP-CLI? and How to move all images from one WordPress website to another using WP-CLI?

Conclusion

I hope that helps give you a high level overview and some tips of working on your WordPress website via SSH.


Was this answer helpful?

One email a month. Endless business benefits.

Don't miss out on WMTWWFY — the newsletter that keeps your website fast, safe, and visible.

« Back
Spinner
aluminium-anthropoid Security Check