Sail Knowledgebase

How to Access Your WordPress Server via SSH and WP-CLI Using Sail CLI

In this article you will learn how to use the sail ssh command to open an interactive shell or run commands on your WordPress server. You will also learn about the sail wp shortcut.

If you like Sail, consider sponsoring us via GitHub!

Authentication

Using passwords to login to SSH is insecure and not recommended, especially as the root user. This is why Sail uses SSH keys exclusively.

When provisioning a server with sail, a new SSH key is generated automatically, and placed in the .sail directory along with its public key. This key is used automatically for any interactions done through the Sail CLI.

If you'd like to add your own SSH keys to your Sail server, you can do so using the ssh key add command.

SSH Shell

To open an SSH shell to your WordPress server, run:

sail ssh

By default, this will open a shell as the www-data user on your server, and change to your WordPress project directory, so you could run WP-CLI and other commands.

If you'd rather login as root, add the --root flag:

sail ssh --root

And remember, with great power comes great responsibility.

To run a single command and exit, use:

sail ssh run <command>

The output and return-code of the executed command will be passed through, so it is safe to use this command in shell scripts.

WP-CLI

We do not recommend using wp ssh to run WP-CLI commands, since there's a more convenient way of doing it with Sail:

sail wp <command>

If you're having trouble with SSH or WP-CLI in Sail, please refer to our getting help section.