---
title: "Manage WordPress over SSH with WP-CLI · CloudSat"
description: "Log in to your WordPress server over SSH with a key, then use WP-CLI to update, back up, search and replace URLs, reset passwords and rescue a broken site."
url: https://cloudsat.io/learn/manage-wordpress-over-ssh-with-wp-cli
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Self-hosting](https://cloudsat.io/learn/topic/self-hosting)

# Manage WordPress over SSH with WP-CLI

Log in to your WordPress server over SSH with a key, then use WP-CLI to update, back up, search and replace URLs, reset passwords and rescue a broken site.

CloudSat team November 18, 2026 7 min read

The WordPress dashboard works until the day it does not: a plugin update ends in a blank page, the only administrator forgets the password, or a domain change sends every page into a redirect loop. SSH and WP-CLI are the way in that still works on that day. This guide sets up a clean key-based login, then covers the WP-CLI commands for routine upkeep and for getting a broken site back.

## Set up a key-based SSH login

Create a key on your own computer, not on the server. On macOS, Linux and Windows 10 or 11, OpenSSH is already there:

```bash
ssh-keygen -t ed25519 -C "laptop"
ssh-copy-id deploy@203.0.113.10
```

On Windows, `ssh-copy-id` is missing; paste the content of `id_ed25519.pub` into `~/.ssh/authorized_keys` on the server instead, as shown in [Connect over SSH from Windows](https://cloudsat.io/docs/ssh-from-windows). Keys for new servers can also be added at deploy time; see [Add and use SSH keys](https://cloudsat.io/docs/manage-ssh-keys).

Then give the server a short name in `~/.ssh/config`, so every later command stays readable:

```text
Host wp-prod
    HostName 203.0.113.10
    User deploy
    IdentityFile ~/.ssh/id_ed25519
```

`ssh wp-prod` now logs you in. Use an ordinary user with `sudo` for this work rather than `root`. Once the key works, set `PasswordAuthentication no` in the SSH server configuration so password guessing stops being possible.

## Run WP-CLI as the right user

WP-CLI is a single file, `/usr/local/bin/wp`; [Install WordPress on a VPS with Nginx and MariaDB](https://cloudsat.io/learn/install-wordpress-on-a-vps-with-nginx) shows the four commands that install it. Run it as the user that owns the WordPress files, usually `www-data`, so files it creates keep the right owner. It refuses to run as `root` unless you add `--allow-root`, and that refusal is worth respecting.

A shell alias saves typing the user and the path every time:

```bash
echo "alias wpx='sudo -u www-data wp --path=/var/www/example.com'" >> ~/.bashrc
source ~/.bashrc
wpx core version
```

The rest of this guide uses plain `wp`; prefix it the way your server needs.

### From your laptop, if you prefer

WP-CLI can also run commands on the server from your own machine through SSH aliases. It needs PHP and WP-CLI on both sides, and it runs as the SSH user, so that user must be able to write the WordPress files. In `~/.wp-cli/config.yml` on your computer:

```yaml
@prod:
  ssh: deploy@wp-prod/var/www/example.com
```

`wp @prod plugin list` then runs on the server and prints locally.

## The commands you will use every week

| Task | Command |
| --- | --- |
| See pending updates | `wp core check-update` and `wp plugin list --update=available` |
| Preview plugin updates | `wp plugin update --all --dry-run` |
| Apply updates | `wp plugin update --all`, `wp theme update --all`, `wp core update` |
| Upgrade the database after core updates | `wp core update-db` |
| Export the database | `wp db export - \\| gzip > backup.sql.gz` |
| Check core files against official checksums | `wp core verify-checksums` |
| List administrators | `wp user list --role=administrator` |
| Run cron events that are due | `wp cron event run --due-now` |
| Clear the object cache | `wp cache flush` |

## A safe update routine

Updates break sites less often than people fear, but they are the moment a break is most likely. A routine that takes two minutes:

```bash
cd /var/www/example.com
wp db export - | gzip > ~/backups/example-$(date +%F-%H%M).sql.gz
wp plugin update --all --dry-run
wp maintenance-mode activate
wp plugin update --all
wp theme update --all
wp core update && wp core update-db
wp maintenance-mode deactivate
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/
```

The last line should print `200`. If a plugin update broke something, reinstall the previous version from wordpress.org, where `5.4.2` stands for the last version that worked:

```bash
wp plugin install some-plugin --version=5.4.2 --force
```

For major WordPress releases, take a server-level copy first. On CloudSat, a [snapshot](https://cloudsat.io/docs/take-a-snapshot) taken from the console gives you a rollback point for the whole disk, files and database together.

## Rescue a broken site

### A blank page or a fatal error after an update

Load WordPress without plugins and themes, so the faulty code cannot stop WP-CLI itself, then switch off the suspect:

```bash
wp plugin list --skip-plugins --skip-themes
wp plugin deactivate some-plugin --skip-plugins --skip-themes
```

Must-use plugins in `wp-content/mu-plugins` still load with `--skip-plugins`, so if the error points there, move that file aside by hand. If you cannot tell which plugin it is, deactivate them all with `--all`, then reactivate one at a time while you reload the site. A broken theme gets the same treatment: `wp theme list --skip-themes`, then `wp theme activate` with one of the default themes listed. The PHP-FPM and web server error logs name the file that failed, which usually points straight at the culprit.

### Locked out of the dashboard

Set a new password without it ever appearing in your shell history:

```bash
wp user update siteadmin --prompt=user_pass
```

If mail works on the server, `wp user reset-password siteadmin` sends the usual reset email instead.

### "Briefly unavailable for scheduled maintenance"

An update that was interrupted leaves a `.maintenance` file in the site's root, and WordPress shows that message to every visitor until it goes away. `wp maintenance-mode status` confirms it, and `wp maintenance-mode deactivate` removes it. Then rerun the update that was cut off, because the plugin or core files may be half replaced.

### "Error establishing a database connection"

Check the database server first, then the credentials WordPress is using:

```bash
systemctl status mariadb --no-pager
wp config get DB_NAME
wp config get DB_HOST
wp db check
```

If MariaDB is down, its journal usually explains why, and a full disk is a common reason. If it runs but `wp db check` fails, the user or password in `wp-config.php` no longer matches the database.

### A redirect loop after a domain or HTTPS change

WordPress stores its own address in two options. Read them, then fix them:

```bash
wp option get home
wp option get siteurl
wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'
```

Old addresses also live inside posts, widgets and settings, often as PHP-serialized data that a raw SQL `REPLACE` would corrupt. `search-replace` understands serialization. Preview first, and leave the `guid` column alone because feed readers rely on it:

```bash
wp search-replace 'http://old.example.com' 'https://example.com' --all-tables --skip-columns=guid --dry-run
wp search-replace 'http://old.example.com' 'https://example.com' --all-tables --skip-columns=guid
wp cache flush
```

### Something looks tampered with

```bash
wp core verify-checksums
wp plugin verify-checksums --all
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp config shuffle-salts
```

The checksum commands compare files with the official copies; plugin checks only work for plugins hosted on wordpress.org. An administrator you did not create is a strong sign of compromise. New salts in `wp-config.php` log every user out, including an attacker holding a stolen session cookie.

## Automate the nightly database dump

Add a job to the `www-data` crontab with `sudo crontab -u www-data -e`. Percent signs must be escaped in crontab lines, and the target directory must exist and be writable by `www-data`:

```bash
15 3 * * * cd /var/www/example.com && /usr/local/bin/wp db export - | gzip > /var/backups/wp/example-$(date +\%F).sql.gz
45 3 * * * find /var/backups/wp -name 'example-*.sql.gz' -mtime +14 -delete
```

A dump on the same disk protects against mistakes, not against losing the server. Copy it somewhere else as well; [Back up your data off the server](https://cloudsat.io/docs/backup-your-data) shows a restic setup.

## FAQ

### Why does WP-CLI say "This does not seem to be a WordPress installation"?

It looks for WordPress in the current directory and its parents. `cd` into the site's root, or pass `--path=/var/www/example.com`.

### Is SFTP not enough?

SFTP moves files, which covers uploads and theme edits. WP-CLI also talks to the database through WordPress itself, so it handles users, options, serialized data and updates that file transfers cannot.

### Does WP-CLI work on a multisite network?

Yes. Commands act on the main site unless you add `--url=https://shop.example.com` to target another one, and `wp site list` shows every site in the network with its address.

### Can several people share one server login?

Give each person their own account and SSH key instead. Removing someone's access then means deleting one key, and the server's logs show who did what.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Self-hosting](https://cloudsat.io/learn/topic/self-hosting)

- [Install WordPress on a VPS with Nginx and MariaDB](https://cloudsat.io/learn/install-wordpress-on-a-vps-with-nginx): Self-hosting Install WordPress on a VPS with Nginx and MariaDB 7 min read
- [Speed up WordPress on your own server](https://cloudsat.io/learn/speed-up-wordpress-on-your-own-server): Self-hosting Speed up WordPress on your own server 7 min read
- [Set up 301 redirects in WordPress: server, plugin or code](https://cloudsat.io/learn/set-up-301-redirects-in-wordpress): Self-hosting Set up 301 redirects in WordPress: server, plugin or code 6 min read
- [Drupal or WordPress: the choice from the server side](https://cloudsat.io/learn/drupal-or-wordpress-on-your-own-server): Self-hosting Drupal or WordPress: the choice from the server side 7 min read
