Unable to configure folder permissions in Ubuntu - linux

I found many related questions and tried to solve the issue but I was not successful. Actually I created an user named "amit" and assigned the group "www-data". I gave permission to the folder using this method
sudo chown -R :www-data /var/www
sudo chmod g+w /var/www
sudo adduser amit www-data
Change folder and file permission recursively:
To change all the directories to 755 (-rwxr-xr-x):
find /var/www -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):
find /var/www -type f -exec chmod 644 {} \;
But in joomla system info when i check i get all directories as non writable.
So I changes this command to
sudo chown -R www-data:www-data /var/www
Surprisingly this worked.
I need to know why the created user didn't work but this one worked, where did I miss something?

Applying chmod 755 (rwxr-xr-x) for directories and chmod 644 (rw-r--r--) for files just makes the writable for the owner, but not for the group. If you want to grant the group write permissions then you need 775 and 664.

Related

Laravel 5: Failed to open stream: Permission denied

I have my project in local development and all it's working fine.
When I pass the project to a rasberry and try to make it works I'm getting some errors I try to find the solution in other questions like this here in stackoverflow but it not works.
When I call to a function who it's working with storage folder I get this error:
With sudo chmod -R 775 storage/
The stream or file "/var/www/html/test/storage/logs/laravel.log" could
not be opened: failed to open stream: Permission denied
And if I change the permission to 777 I get this error:
file_put_contents(/var/www/html/test/resources/views/projects/problema.blade.php): failed to open stream: Permission denied
How should be the permission of the folder to make it works?
This is what i used to do for the linux installations :
sudo usermod -a -G apache your_user
sudo chown -R your_user:apache /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
You should be fine with these permissions.You can replace the group and user and you need. Never provide a 777 permission to any of the folders.

How to restore correct subversion directory permissions?

The other day I thougt I should make my server a little more secure.
I figured I had way too many directories that are read-open to others and could potentially be a risk in case someone finds his way into the system.
I then removed read-, write- and execute-permissions for others on certain directories:
chmod -R o-rwx /home/*/
chmod -R o-rwx /etc/apache2
chmod -R o-rwx /var/www
chmod -R o-rwx /opt
chmod -R o-rwx /mnt
chmod -R o-rwx /media
Now, about two days later I wanted to access my subversion-server located at /home/svn and I got an error 500.
I guess I messed up the permissions on the subversion directory. But I don't understand why it would need 'others'-permissions. I thought it runs as root and can read/write/execute anything it needs.
EDIT: I looked into svn-error.log and saw this:
[Wed Nov 29 14:34:29 2017] [error] [client 2003:cd:dbc6:5c00:ec08:696:5b01:bf20] (13)Permission denied: Could not open password file: /etc/apache2/dav_svn.passwd, referer: http://<host>:<port>/svn/myrepo
What permissions are the correct ones to set and why?
I found the answer here: https://ubuntuforums.org/showthread.php?t=1288812
I was able to restore the correct permissions for folders and files in three commands:
find /etc/apache2/ -type f -exec sudo chmod 644 {} \;
find /etc/apache2/ -type d -exec sudo chmod 755 {} \;
sudo chown -R root:root /etc/apache2

How do I change file permissions in Ubuntu [duplicate]

This question already has answers here:
How do I change permissions for a folder and its subfolders/files? [closed]
(19 answers)
Closed 8 years ago.
In Ubuntu I want to change the file permissions of a whole folder and all its sub folders to read/write by anybody
I have tried sudo chmod 666 /var/www and sudo chmod 755 /var/www without success
update
I have since found that changing privileges can also be done in the GUI by opening nautilus as sudo.
So that you don't mess up other permissions already on the file, use the flag +, such as via
sudo chmod -R o+rw /var/www
If you just want to change file permissions, you want to be careful about using -R on chmod since it will change anything, files or folders. If you are doing a relative change (like adding write permission for everyone), you can do this:
sudo chmod -R a+w /var/www
But if you want to use the literal permissions of read/write, you may want to select files versus folders:
sudo find /var/www -type f -exec chmod 666 {} \;
(Which, by the way, for security reasons, I wouldn't recommend either of these.)
Or for folders:
sudo find /var/www -type d -exec chmod 755 {} \;
Add -R for recursive:
sudo chmod -R 666 /var/www

Are these LAMP permissions secure?

I have a LAMP server where I've run the following commands to set permissions of files in /var/www:
groupadd web
usermod -a -G web my_user
chown -R root:web /var/www
chmod -R 775 /var/www
chmod -R g+s /var/www
My goal is to have all files writable by any member of the "web" group. Is there a secure way to allow file uploads (e.g. within Wordpress) without changing the file ownership? Note: this is a private server.
One way of applying permissions to just directories is to use the find command. For example:
# Set the owner and group on everything.
chown -R root:web /var/www
# Make *directories* read/write/execute and set the `sgid` bit.
find /var/www -type d -print | xargs chmod g+rwxs
You don't want to run chmod -R 775 /var/www because this will make all your files executable, which is probably not what you want.

file permissions security apache

I'm trying to figure out what is the best file permissions/user/groups for files under my document root?
I have the following file structure
/home/user/public_html/
under public_html are all of my php files and directories.
I have one directory /home/user/public_html/files/ where people upload images to that directory.
What is the most secure way to distribute file permissions/groups/user so that apache can properly display the php files and directories?
Should I make public_html owned by apache? What group should I use for public_html?
thanks!
My Favourite mix of permissions for apache is to give it ownership of apache:apache, all folders chmod to 550 or 555, and all files chmod to 440/444. I suggest the following:
/home/user/public_html/ owned by apache:apache with permissions 555 (read/x by everyone)
/home/user/public_html/files/ owned by apache:apache with 775 (read/write/x by root/apache, read/x by all)
First need to find which user running https / apache2 server
ps -aux | grep apache2
Most of times apache or www-data comes
We need to set this user
chown -R www-data:www-data /var/www/html
Then file permission should be 644 and folder 755
we can do that using find command
find /var/www/html -type f -not -perm 644 -exec chmod 644 {} \;
find /var/www/html -type d -not -perm 755 -exec chmod 755 {} \;

Resources