Whenever I upload a new file to my server, I have to chown -R apache:apache /dir in order for it to be accessible.

Is there an easier way around this?

  • Is this your own server? Then we need to know what ftp-server you are running. In every ftp server you can change the configuration so that uploaded files get the right user:group and permissions. It is also possible to work with inherited permission from the parent directory or with ACL (Access Control List) but it is far easier to set it in the ftp-server.
    – Rik
    Nov 27, 2013 at 19:10
  • Unless you're FTPing into your server as the user apache:apache then yes, you need to do this, be it manually or via some sort of FTP client/server config
    – Jobbo
    Nov 29, 2013 at 14:33
  • @Jobbo How might I go upon uploading as the user apache:apache?
    – Travis
    Nov 30, 2013 at 21:41
  • @Travis You could login to ftp with username apache (if you've got a password for that). Otherwise you need to change the config of your ftp-server. Is this your own server? And what server-daemon are you running? VSFTPD or something else?
    – Rik
    Nov 30, 2013 at 22:02
  • @Rik I am using vsftpd This is also my server. I have root access and I have been uploading everything as root.
    – Travis
    Dec 2, 2013 at 6:56

2 Answers 2


Most likely, what is actually needed for the files to be accessible is that their group is set to apache. You can easily set it by default for new created files by running :

find /path/to/root/directory/of/website -type d -print0 | xargs -0 chmod g+s

This will set the setgid flag on all sub-directories too. With this flag set, any new file created in there will inherit the group of its parent directory. (-print0 and -0 options are designed to handle correctly spaces in filenames)

Make sure ownerships of files are correct before running it. If unsure, you can fix it the same way :

find /path/to/root/directory/of/website -print0 | xargs -0 chown apache:apache
  • And what about a new directory he creates with the ftp-program?
    – Rik
    Dec 1, 2013 at 9:48
  • They should inherit as well, as long as the ftp-program does not explicitly changes the group.
    – Levans
    Dec 1, 2013 at 14:27
  • Yeah, that works. I think i was confused with "user"-part. That can't be inherited without using ACLs. But just for the group part the setgid works fine (+1). If the ftp-program does set the group... well... then there is nothing else to do then change its configuration. I did just test it with VSFTPD and with that it works. (The group is not set to the one defined in the vsftpd.conf but takes it from its parent directory)
    – Rik
    Dec 1, 2013 at 15:22
  • @Levans when I run that command I issue 'find /var/www/travisingram.net/public_html -type d | xargs chmod g+s' and the permissions aren't affected. Another way I know of that it has not changed is in WordPress, whenever I update/install a plugin it'll require FTP or SFTP. Now, if its been chown with apache:apache I shouldn't se that. Did I not do the command correctly? I am running vsftpd
    – Travis
    Dec 2, 2013 at 7:02
  • @Travis are you running this command with sufficient rights (as root user) ? When displaying the file permissions (with ls -l), you should see an S instead of the x for group permissions on directories.
    – Levans
    Dec 2, 2013 at 8:43

Here is what you could do with VSFTPD:

You can set the following 2 options in you vsftpd.conf:


guest_enable, if enabled, makes sure all files are uploaded as user/group apache.

Please note that this will only work for files uploaded via FTP. If you copy a file in Linux itself to your www directory, this will not adjust the permissions.

That's why, if you're also accessing that directory via the filesystem, it is best to use the chmod g+s-method Levans suggested.

find /var/www/site/public_html -print0 | xargs -0 chown apache:apache
find /var/www/site/public_html -type d -print0 | xargs -0 chmod g+s

If enabled, all non-anonymous logins are classed as "guest" logins. A guest login is remapped to the user specified in the guest_username setting.

Default: NO

See the boolean setting guest_enable for a description of what constitutes a guest login. This setting is the real username which guest users are mapped to.

Default: ftp

  • Would apache have the same password as root? Guess not, decided to give it a go before I asked. So is it without password open for general use? Sorta confused here.
    – Travis
    Dec 3, 2013 at 0:16
  • You shouldn't use root to login to ftp. There is a username ftp setup for it. But it doesn't matter with what user you login (you can setup ftp users in the config), you need to tell the ftp-program to write the files as apache:apache because your webserver needs access. (Even if user apache has no password/ftp access the files can still be written with that user as long as vsftpd assigns it to that user. That's where these lines are for)
    – Rik
    Dec 3, 2013 at 0:30
  • And only if you enabled anonymous, anyone could login without a password. If it's disabled you can login with the users you have enabled access for ftp. This could be from standard Linux used to a simple login.txt where you defined users and passwords. That depends on your config file. guest_enabled is a bit confusing because it has nothing to do with 'guest'-access but makes vsftpd write a different user (remap) for 'normal' users.
    – Rik
    Dec 3, 2013 at 0:35
  • how might I go upon setting passwords for it then? I do not know the specific commands for vsftpd.
    – Travis
    Dec 3, 2013 at 0:57
  • Seen you post on that other question I made earlier. I forgot about making a question previous. I found that I had this one actually after I created that one. Anyways, I just removed it.
    – Travis
    Dec 3, 2013 at 0:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .