How to automatically setup group in subdirectory in Linux - linux

I would like to ensure that in only one particular directory on linux server will have newly-created directory setup particular group?
I.e.:
I have directory /data with ownership "user1:global_group" and every new subdirectory should have group ownership the same. Once I create directory by using mkdir /data/subdir1 under user1 or user2 the ownership is "user1:grp_user1" or "user2:grp_user2".
How can I manage the subdirectory ownership?
Many thanks for any ideas ...

You need chmod for that.
Apply this: chmod g+s directory on a parent directory. Every newly created file and directory, recursively, will have the group of the parent directory.
So:
chgrp target_group target_directory
chmod g+s target_directory
mkdir -p target_directory/subdirectory/another_one
ls -l target_directory/subdirectory/another_one
And observe, how another_one directory has the desired group.

Use -R or --recursive option. And try chgrp --help first.

Related

Why do I have to enter "sudo chmod -R 0777 folder1" repeatedly if some new folder is created inside folder1

I have to give access to some launcher inside "folder1".
Whenever a new folder is created inside "folder1", I have to again give the permissions by typing sudo chmod -R 0777 folder1. Is there a way that I could permanently enable 0777 for a particular folder. No matter how many new subfolders are created inside it.
I tried and it works. But I have to give the permissions again and again
sudo chmod -R 0777 folder1
You need to umask command in your ".profile" file in your home path. Then restart your session and create new folder. All the folders will get fill permission by default for all users.
Command $ umask 000
Open .profile file
Insert command "umask 000" in .profile file and save it.
Restart the session and create folders.
I will try setfacl to set ACLs, e.g.:
setfacl -m d:o::7,d:g::7,d:o::7 mydir/
setfacl -m o::7,g::7,o::7 mydir/
Actually, this way if you create directories under mydir they will have 0777 permissions and files will have 0666.
Hope it is useful
Cheers

User cannot create file linux

may I know a command for root to change the mode to make the user able to create files.
I tried multiple times but I can seem to solve it.
[root#master ~]# useradd -d /opt/hadoop hadoop
useradd: cannot create directory /opt/hadoop
What are the permissions on /opt/hadoop? If you created the directory manually as root then it's probably owned by root and the user has no access to it - you'd need to chown -R it to the correct ownership.
chmod 755 /opt
chown root /opt
chmod 755 /opt/hadoop
chown -R user:user /opt/hadoop

Setting directory in Linux

Someone please advise how to set the directory to chown root:root and chmod 0600, so that everything in it was created or copy the same settings as configured directory? thank you
Your question is not that clear ... but I think that perhaps what you're looking for is recursive application to apply chown and chmod settings to all files in the directory. This can be done (in both cases) using the -R flag, for example:
chown -R root:root mydir/*
I think you are looking for chmod -R 0600 * and chown -R root:root *, but your question is not entirely clear.
I think you are looking for the -R (recursive) flag - you can use
chown -R root:root /your/directory/full/path
and
chmod -R 0600 /your/directory/full/path
If instead you're copying an existing directory and want to retain permissions you can use
cp -a /current/path /new/path
and the -a flag will keep ownership and permissions the same
I think I understand your question now: you're trying to set the default permissions and ownership for new files in the directory.
For ownership, if you add yourself to the group that owns the directory (root in this case), then new files you create will be owned by that group.
For permissions, you can set default permissions for new files using umask:
umask 077 # grant only user r/w permissions
or using setfacl: see this answer for more information.

Setting Drupal root directory to 777

A company mine is working with is having permissions issues for uploading files (via FTP). We found a workaround of putting everything to 777 (not my first choice, but ease of use trumps security here).
The problem with this is that Drupal breaks upon putting the root directory as 777.
Why is this? How can I change that?
Typically your files directory should be:
chmod -R 775 files
But also make sure your owner and group are correct. The owner in this case should be your ftp user. And your group should be the apache user.
chgrp -R apache_user files
chown -R ftp_user files
Having problem to upload files with ftp or with drupal? Drupal need write permission in sites/default/files to save images and css etc.
Maybe its problem with owner too?
Check this page: http://drupal.org/node/244924
The problem with this is that Drupal breaks upon putting the root
directory as 777.
Actually you need to change not root of Drupal directory but the directory sites/default/files.
If you want to do that in easiest way change this directory permissions to 777:
cd <your Drupal root>/sites/default
chmod -R 777 files
The secure way is to set your WWW user (e.g. www-data) as an owner of this directory:
cd <your Drupal root>/sites/default
chown -R www-data files
chmod -R 775 files
Also you can add your group (e.g. my_group):
chgrp -R my_group files

How to set rights to all existing and new files of specified directory

I have an Ubuntu server, i have a directory /testftp/. In this directory i have many other directories and files in them, how can i set to all existing and new directories and files in this directories rights - 755?
/testftp/ group is testclient
Thanks!
upd
using
chmod -R 755 /testftp/ all ok, but when i create/upload new file or directory it has 600 rights
check the following manual pages
man chmod
man umask
Try chmod -R 755 /testscript/
-R means recursive and it applies to all sub directories.

Resources