Although this question is old, the answer needs to be brought up to date.
Let's consider the following :
You state you gave yourself "administrative privileges". And by the accepted answer here user and group www-data
now has permissions to write to the directory in question.
Out of the box, when you install a LAMP stack, /var/www
directories and files are recursively owned by user and group root:root
, unless you have changed the default ownership/permissions. Which in your case is true. To confirm :
cd /var/www && ls -l
The output with default LAMP stack installation :
drwxr-xr-x 2 root root 4096 Sep 1 19:53 html
Above, there is a reason why /var/www
and html
directories are owned by user and group root:root
on a default level, it gives read/executable permissions only to others
which includes www-data
. This conforms to least privileges security aspect. We wouldn't want an attacker to gain access to the www-data
user/group which is the most vulnerable here, with permissions to write
a script and takeover the server!
This should help understand the default permissions of the html
directory created when apache/nginx was installed :
Owner |
Group |
Other |
read, write & execute |
read & execute |
read & execute |
4+2+1=7 |
4+1=5 |
4+1=5 |
What we can do to safely use your_domain
directory to transfer directories and files in a graphical interface with the necessary permissions is to :
Assign ownership to the directory in question :
sudo chown -R $USER:$USER /var/www/your_domain
Now check the permissions of /your_domain
:
cd /var/www && ls -l
From the output here we can clearly see that your_user
is owner and group and that others ( www-data
) have read/execute permissions only. Which is a safe way to not compromise the web server and other users directories :
drwxr-xr-x 2 root root 4096 Sep 1 19:53 html
drwxr-xr-x 2 your_user your_user 4096 Sep 2 10:49 your_domain
Reload Apache :
sudo systemctl reload apache2
Once this is done, here is a "simple" way to add files to /var/www/your_domain
:
Install vsftpd on your server and FileZilla on the client machine :
You can follow this guide to install and setup both vsftpd and FileZilla.
Just replace the /home/username/ftp/files
to suite your needs and substitute where needed username
( in the guide username is sammy
) with your_username
.
Note : You may need to add this entry pasv_enable=Yes
to your /etc/vsftpd.conf
file for Windows client.
After vsftpd setup is done, we create the directory /home/username/ftp/files/www
and mount /var/www/your_domain
to this directory.
- Create the mount directory :
mkdir /home/username/ftp/files/www
- Edit
/etc/fstab
to add the mount point :
/var/www/your_domain /home/username/ftp/files/www none defaults,bind 0 0
Source : here
Reboot the server.
Now the previous method of creating a permanent mount will work with a minimal image ( i.e. Container ) where it's fstab
file indicates UNCONFIGURED FSTAB FOR BASE SYSTEM
, this will NOT work with physical servers.
So, if you still insist on FTP a temporary approach would be to bind the directories ( This method cannot survive system reboot ) like so :
sudo mount --bind /var/www/your_domain /home/username/ftp/files/www
Another, and permanent approach, would be to simply use a symbolic link. Keep in mind with this method you would need to choose where Protocol: in FileZilla -> SFTP-SSH File Transfer Protocol. To create the symbolic link we cannot use an absolute path ( i.e. /var/www/your_domain
). We will use the relative path from /home/username/ftp/files/www
to /var/www/your_domain
. The command would be :
sudo ln -s ../../../../../var/www/your_domain /home/username/ftp/files/www
You will find a guide for SFTP setup here.
And finally here is a simple way to edit files in /var/www/your_domain
:
Edit the files on your development machine.
Stop your web server, example : sudo service apache2 stop
or sudo service nginx stop
.
Add the files with FileZilla with protocols SFTP(symbolic link method) or FTP(mount method).
Restart the web server : sudo service apache2 start
or sudo service nginx stop
.