Wordpress updates via SSH

So, you hate to manually upload theme and plugin upgrades to your Wordpress installation and you for sure don’t want to install FTP on your server since you work over SSH/SCP?

Yep, me too.

Wordpress can handle updates via SSH with SSH-keys!
First of all you need to have php5-ssh2 installed. Oh, yeah, this guide is for Debian/Ubuntu. Everybody else need to search how to compile PHP with the SSH2 package.

apt-get install php5-ssh2

Lets generate some SSH keys for WP to use.

ssh-keygen

You will be prompted where to put the file and for a password. Name the file something like id_rsa-wp so you know what it is for. Leave password empty if you want.
Now, we have to put the public key in a file called authorized_keys so SSH can find it.

cd ~/.ssh
cat id_rsa-wp.pub >> authorized_keys

If WP/Apache run as your user, this is all you need to do. If it runs as www-data, you ned to set permissions

chmod 644 id_rsa-wp*

The next step is to put some info in your wp-config so you don’t have to enter the file path every time it’s time for an update.

define('FTP_PUBKEY','/home/your_user/.ssh/id_rsa-wp.pub');
define('FTP_PRIKEY','/home/your_user/.ssh/id_rsa-wp');
define('FTP_USER','your_user');
define('FTP_PASS','');
define('FTP_HOST','your.server.com:22');

And thats it!
Just click SSH2 on the update/install page in WP and smile!