Configure SSH2 Access for Updating WordPress

WordPress is one of the most popular blogging platforms on the Internet. One of the first things I do when I setup a new WordPress installation is harden it. You can read about a number of my suggestions in the article Secure Your WordPress Installation. However, one of the more complex activities I undertake is securing the upgrade facility so that it uses SSH for handling all of my site’s updates.

This is for Ubuntu 10.04 LTS:

Create a “wordpress” user that will be used to manage your site.

[shell]
% sudo adduser wordpress
[/shell]

Add the following lines to your wp-config.php, I usually put mine right after the Language definition:

[shell]
/**
* Define Upgrade FTP Usernames and Passwords
*/
define(‘FTPBASE’, ‘/usr/local/sites/mysite/wordpress/’);
define(‘FTP
CONTENTDIR’, ‘/usr/local/sites/mysite/wordpress/wp-content/’)
;
define(‘FTP
PLUGINDIR ‘, ‘/usr/local/sites/mysite/wordpress/wp-content/plugins/’);
define(‘FTP
PUBKEY’, ‘/home/wordpress/.ssh/idrsa.pub’);
define(‘FTP
PRIKEY’, ‘/home/wordpress/.ssh/idrsa’);
define(‘FTP
USER’, ‘wordpress’);
define(‘FTPPASS’, ”);
define(‘FTP
HOST’, ‘localhost’);
[/shell]

Edit each of the variables for your installation.

Create an SSH public/private key pair for your wordpress user:

[shell]
% sudo su – wordpress
% ssh-keygen
[/shell]

When prompted to enter a password, just hit return to create the private key without a password.

Add the public key to wordpress’ authorized_keys file:

[shell]
% cp .ssh/idrsa.pub .ssh/authorizedkeys
% exit
[/shell]

Set permissions on the private key so Apache/WordPress can access it:

[shell]
% sudo chgrp www-data /home/wordpress/.ssh
% sudo chmod 750 /home/wordpress/.ssh
% sudo chown www-data /home/wordpress/.ssh/id_rsa
[/shell]

Install php SSH2 libraries:

[shell]
sudo apt-get install php5-dev
sudo apt-get install libssh2-1-dev
sudo apt-get install libssh2-php
[/shell]

Test to ensure PHP sees the new SSH2 library:

[shell]
% php -m | grep ssh2
[/shell]

It should output “ssh2”

Restart Apache so it pulls in the new PHP libraries:

1

% sudo service apache2 restart

Now access your Plugins page, and when you add, update, or delete a plugin you should see a screen like this:

WordPress SSH Connection Information

You should only see this screen the first time you use this configuration. Select “SSH2” from the Radio Buttons and “Proceed”.

You will now be using SSH access to/from your server to handle all updates.

Featured howto Security ssh ubuntu wordpress
Tweet Post Share Update Email RSS

Leader, Mentor, Challenger, Educator, Network Engineer, System Administrator, Developer, Hacker, Writer, Diver, and Technology Explorer.