Proper directory permisions for module installation? So I'm trying to understand the correct permissions for file directories in order to install a module. I've installed drupal, and I try to install a module, which looks like so:


But When I click install it takes me here:



I then wanted to test if it was permissions preventing it from installing, so I chmod'd everything to 777 in the sites folder just to see, and yes, the module then installed easily and correctly. But of course, 777 on everything is insecure, so I quickly installed drupal again from scratch. So now when I check the permissions they look like this

html/sites$ ls -l
total 16
drwxr-xr-x 5 6226 6226 4096 Jun 17 18:38 all
dr-xr-xr-x 3 6226 6226 4096 Jul 19 20:08 default
-rw-r--r-- 1 6226 6226 2365 Jun 17 18:38 example.sites.php
-rw-r--r-- 1 6226 6226  904 Jun 17 18:38 README.txt


So after an installation the all folder has r-x permissions and the default has r-x as well for group and other. (A side question being, what do I make of the user and group, "6226", "4096","2365", and "904"?) 

The "modules" folder, inside "all" folder where they get downloaded is also set to r-x. 

html/sites/all$ ls -l
total 12
drwxr-xr-x 2 6226 6226 4096 Jun 17 18:38 libraries
drwxr-xr-x 2 6226 6226 4096 Jun 17 18:38 modules
drwxr-xr-x 2 6226 6226 4096 Jun 17 18:38 themes


I don't know if this seems right to me. Shouldn't it be able to write to the folder to download the module from an external source?

Thanks for all the feedback in advance, I look forward to hearing what people have to say.

Edit, more details:

Linux myhostname 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

ubuntu@myhostname:/var/www/html/sites/all/modules$ ls -la
total 12
drwxr-xr-x 2 www-data 6226 4096 Jun 17 18:38 .
drwxr-xr-x 5     6226 6226 4096 Jun 17 18:38 ..
-rw-r--r-- 1 www-data 6226  952 Jun 17 18:38 README.txt

Okay! So. after reinstalling and repeatedly chowning folders until I made it past that request for FTP details, I finally got it to ATTEMPT to download the file. All I had to do after a fresh install was sudo chown www-data /var/www/html/sites/default. What confuses me is why that would work. Beause before and after chowning, the permissions were dr-xr-xr-x 3 www-data 6226 4096 Jul 20 09:03 default for the default folder. So my understanding is that the owner, group, and others could all all read and execute, so why would changing the owner even matter?
Now when attempting to "Install from a URL" after chowning default, a loading bar appears and says "Completed 100%", and then this screen appears instead of the FTP login request:
The module directory has contested ownership. In your case, using the FTP set up from the browser, the modules directory (and subdirectories and files) need to be owned by the FTP user you are logging in with.

For example: if you are ftp-ing in with myusername then the ownership on the directories and files are most likely be myusername. That is the default configuration for most FTP servers (ProFTPd for example).

$ chown -R [myusername] [pathtomodules]


If you are updating Features (or configuration in Drupal 8) from the Drupal backend you'll want the modules directory owned by the same user as your web service runs as. Then you can have your permissions set to something more reasonable.
If you grep ps for Apache, nginx or httpd you should discover the user that's running the process. 

$ ps aux | grep -i 'www\|apache\|nginx'
$ chown -R [username] [pathtomodules]


And finally if you are using drush dl you'll need the owner to be your SSH user.

In all cases you can set the strongest permissions with the following. Remember the webserver needs read on all files and execute on all directories. This command will give you 755 on directories and 644 on files.

$ chmod -R u+rwX,go+rX,go-w [pathtomodules]

The first two numbers in your ls command are user and group. That may be a numeric match for your web service user above. The third column is size.