Enable SSH update/install WordPress

WordPress Tutorial: Using SSH to Install/Upgrade

This tutorial will guide you step by step on how to setup your server so you can install new plugins and upgrade existing plugins using an SSH2 layer in PHP and WordPress.

What is WordPress?
WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on hundreds of thousands of sites and seen by tens of millions of people every day.

What is SSH[2]?
SSH (Secure Shell) is a protocol allowing a secure channel to be established between a web server and a client’s local machine. Many web hosting companies now offer SSH for greater security.


Tutorial Pre-requisites

Install ssh2 onto your server. Here’s a tutorial on how to do this Iinstall ssh2 Centos


Step 1: Generating the server-side RSA keys

ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory ‘/home/user1/.ssh’.
Enter passphrase (empty for no passphrase): (just hit enter, no need for a password)
Enter same passphrase again: (same thing, hit enter again)
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx user1@server1.example.com

The xx:xx:xx etc. will be replaced with your actual fingerprint.

Step 2: Creating an ‘authorized_keys’ file

cd .ssh
cp id_rsa.pub authorized_keys

Step 3: Setting the proper file permissions

cd ~/
chmod 755 .ssh
chmod 644 .ssh/*

Step 4: Choosing the ‘SSH’ option

In this tutorial, I opted not to use a password, so you do not need to enter a password.

Step 5: Click “Proceed”

The last step is to click the proceed button and it will install a new plugin or upgrade an existing plugin via the integrated SSH layer in WordPress. You should see results something like this…

Ensure Apache is the owner of the wordpress build

# Let Apache be owner (on centos this would be apache:apache)
sudo chown -R www-data:www-data /path/to/wordpress/build/

== Optional ==

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.

define('FTP_PUBKEY','/home/user1/.ssh/id_rsa.pub');
define('FTP_PRIKEY','/home/user1/.ssh/id_rsa');
define('FTP_USER','user1');
define('FTP_PASS','');
define('FTP_HOST','server1.example.com:22');

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.