Enable plugin and theme updates over SFTP on WordPress

Here's a quick post on making WordPress SFTP friendly.

If using FTP, plugin and theme updates work and all is nice and dandy, but please god have mercy on you if SFTP.

This screen will get familiar for sure:

WordPress FTP credential prompt
WordPress FTP credential prompt

Configuring WP

You can fill in the FTP credential prompt every time, or put the following to wp-config.php file.

// Path to your key files, if you got multiple key files remember to
// use the right key here.
define('FTP_PUBKEY', '/home/user/.ssh/id_rsa.pub');
define('FTP_PRIKEY', '/home/user/.ssh/id_rsa');

// The SFTP user goes here.
define('FTP_USER', 'user');

// This was a culprit for me once, didn't work without it.
// Possible values: "direct", "ssh2", "ftpext", or "ftpsockets".
define('FS_METHOD', 'direct');

// Hostname, define a custom port here if in use.
define('FTP_HOST', 'example.com:73000');

See more possible options here.

Additional server components to install

Also, might need to have libssh2-php installed:

$ sudo apt-get update && apt-get install libssh2-php

After install restart your webserver, most likely it’s Apache or NGinx:

# NGinx
$ service nginx restart

# Apache
$ service apache2 restart

Hope this was helpful. Have a nice day!

Club-Mate, the beverage → club-mate.fi