WordPress update via SFTP (SSH) easily on Ubuntu 12.04

It’s not always possible to use FTP on a WordPress server. This is the case when it is hosted on a virtual server (for instance) or behind a firewall.

However, the FTP protocol is used locally when you upgrade your WordPress plugins (or WordPress itself), and thus can be used in any case. But there are some situations when you’ll want to avoid installing FTP service just for that usage.

So, how keep your WordPress up-todate in that conditions, while the update screen only propose FTP or FTPS protocols (FTPS has the same constraints than FTP, and must not be mixed up with  SFTP)


When browsing the web, one can find this page which gives instructions to activate SFTP transfert (thru SSH). WordPress is connecting locally to its own server when upgrading. You just have to install a SSH2 extension for PHP.

Unfortunately, the procedure explained in the above page is painful, and does not work so well. Instead, a very simple solution does exist :

After that, you just have to restart your Apache server, and the update screen will give a third option : SFTP

For the connexion to work, you’ll have to define a public/private key pair for the owner of the wordpress files.

The add the public key in the list of authorized incoming connexions

At last, change the access rights to allow WordPress to read those keys. Be careful, because the official docs ask to allow the read access to everyone on the private key, which is an obvious security threat ! It’s sufficient to limit read access to the www-data group with :

Done . You can now update and upgrade WordPress with this SSH connexion.
(Just a note : the  password field is not the user’s password, but the pass phrase of the key. If you did not define any, it can be left empty)

If you want to automate the process a bit more, there are a few more things you can do to make it even easier.
If you open up your wp-config.php and add these lines, it will make the process smoother.

Now, when you click “upgrade” or “install” on a new plugin, it will bypass the first screen you saw above asking for the details. It will automatically go into the process and start the install/upgrade.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Crocoware technical blog