Websites · 2 min read
SSH Access and SSH Keys for WordPress Hosting
SSH gives you a secure command-line connection to your WordPress server. Use it to run WP-CLI commands for plugins and themes, import or export data, clear caches, change settings, and manage files. It's meant for people comfortable with the command line.
SSH only uses keys, not passwords, for extra security.
Step 1: Create an SSH key
Mac
- Open Terminal.
- Run
ssh-keygen -t rsaand press Enter at each prompt. - Copy the public key:
pbcopy < ~/.ssh/id_rsa.pub
Linux
- Open a terminal.
- Run
ssh-keygen -t rsaand press Enter at each prompt. - Copy the public key:
cat ~/.ssh/id_rsa.pub | xclip -sel clip
If
xclip isn't installed, install it first: sudo apt install xclip (Ubuntu), sudo pacman -S xclip (Arch), or sudo yum -y install xclip (Fedora/CentOS).Windows
- Open PowerShell.
- Run
ssh-keygen.exe -t rsaand press Enter at each prompt. - Copy the public key:
Get-Content .ssh\id_rsa.pub | Set-Clipboard
Only ever share the public key (the
.pub file). Keep the private key on your computer.Step 2: Add the key to your hosting dashboard
- Open your site in the WordPress hosting dashboard.
- Go to Advanced Settings > Server Settings.
- Turn on SSH Access.
- Scroll to SSH Keys Manager and click Import New Key.
- Paste your public key and give it a name, like "Jane's MacBook". Leave the passphrase blank unless you set one.
- Click Import. The key is authorized automatically.
Step 3: Connect
- On the Server Settings tab, find your host (IP address) and username.
- In your terminal, run
ssh yourusername@yourhostipwith your own values. - The first time, type
yesand press Enter to trust the server. - Go to your site folder:
cd public_html
Handy WP-CLI commands
- List plugins:
wp plugin list - Clear the WordPress cache:
wp cache flush - Clear the CDN cache:
wp cdn purge
Manage keys
- Delete keys you no longer use in SSH Keys Manager.
- Import a key for each computer or team member.
- Replace keys from time to time for better security.
Troubleshooting
- Can't connect? Check the key is authorized and the username and host are right.
- Clipboard command fails on Linux? Install
xclip. - Key has a passphrase? Run
ssh-add ~/.ssh/id_rsafirst.