in ,

How to Edit Webroot (/var/www) Files via SFTP

SFTP and FileZilla are just as good as any FTP program

If you've followed my guide to setting up your own server and using WordOps to install and manage your WordPress site, you've probably realized that I don't install any FTP server, such as PureFTP or VSFTP.

Firstly, it's always best to install the minimum number of apps and packages that are required to achieve what you want (another reason I stay away from control panels like cPanel and the like). Secondly, we already have a perfectly valid method of accessing and editing the files on our server, including our WordPress files within the /var/www directory, courtesy of SFTP.

SFTP stands for SSH file transfer protocol and, as the name suggests, it is like an FTP server that runs on SSH. You will recall that we used SSH extensively to setup our server in the first place, and we also use it to execute various WordOps commands (like adding a new WordPress installation to our server).

The beauty of SSH is that it can also list, edit and transfer files, just like a traditional FTP server. Of course, on it's own, the shell prompt is just nowhere near as intuitive because all the commands would need to be entered manually in text via the shell editor interface, as opposed to the graphical user interface you might be used to in your favorite FTP client, like CrossFTP or FileZilla.

However, FileZilla supports SFTP too (as do many other FTP apps)!

You can login via SFTP to you server, and then just press/click the buttons in FileZilla as you normally would. FileZilla will list, download, upload and edit the files and folders you want to manage, just like a normal FTP client. Check out the image below for the settings you'll need to use. "Host" is the IP address of your server, and the port is the port you setup for SSH when you set the server up.

In terms of what user you should login with (the "user"), we have disabled login via root in our SSH config file, so that won't work. And while you could technically login as another system user you create, they won't have permission to edit the files in your /var/www directory, which is we want, without some further tweaking.

So, what I recommend doing in this case, is amending the user "www-data" so that you can login as "it" via SFTP and manage your files as you wish - all the files in your webroot will be owned by "www-data" and that is the user created by nginx when that software is installed by WordOps. "www-data" manages your web server files, reading them and serving them as your website, so it already has the permissions we required. We just need to alter the account so that we can utilize it with SFTP.

First, we change its shell to /bin/bash (the "shell" is the program on your system that interprets and executes commands). "/bin/bash" is the most common shell in Linux systems. Execute this command in your SSH client:

chsh -s /bin/bash www-data

Then we need to setup a strong password for the user "www-data". Do that with this command:

passwd www-data

Now you can head back to FileZilla, enter the username "www-data" and the password you created in the settings for your site, and login. You can then edit your web server files just as you would normally with a FTP client - you'll find them under /var/www/.

Written by Matt

I've been running web hosting servers and building websites for myself using Wordpress for 14 years. My network of sites get a TON of traffic and I use various models to monetize them - mainly display ads and affiliate marketing. Along the way I've picked up hundreds of tips and tricks that I think would be useful for anyone looking to make a website and here is where I'm going to share them. Find me on Twitter too.

Leave a Reply

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

How to Identify & Find Which WordPress Plugin a Website is Using