Change user and group of files - linux

I want to know is it possible to change the files user and group to same as user and group of the parent automatically.
For eg. Existing issue
getfacl /home/Test/UPS/
getfacl: Removing leading '/' from absolute path names
# file: home/Test/UPS
# owner: user1
# group: basegroup
user::rwx
group::r-x
other::r-x
ls -l /home/Test/UPS/
-rw-r--r-- 1 user1 basegroup 1450 Jul 12 11:54 file.edi
ls -l /home/Test/UPS/
-rw-r--r-- 1 user2 group2 1450 Jul 12 11:54 file.edi
my group2 is part of basegroup
I want files with permission as below automatically whenever file comes into /home/Test/UPS/ directory.
ls -l /home/Test/UPS/
-rw-r--r-- 1 user1 basegroup 1450 Jul 12 11:54 file.edi
Please help...

I know you can use force group and force user for samba mounted directories, but am not aware of any way of automatically overriding user and group in local directories

Related

No rights to view file as member of root group

I am in the group root who owns a file and all the directories above. Why do I have no access to this file? CentOS 7
$ ls /etc/systemd/system | grep parts.service
ls: cannot access /etc/systemd/system/parts.service: Permission denied
-????????? ? ? ? ? ? parts.service
With SUDO:
$ sudo ls /etc/systemd/system | grep parts.service
-rw-rw-rw- 1 root root 563 Feb 13 09:59 parts.service
Checking for an ACL:
$ sudo getfacl /etc/systemd/system/parts.service
getfacl: Removing leading '/' from absolute path names
# file: etc/systemd/system/parts.service
# owner: root
# group: root
user::rw-
group::rw-
other::rw-
My groups:
$ groups
root wheel docker poweruser
Parent directories
drwxr-xr-x 155 root root 12288 Jul 17 09:04 etc/
drwxr-xr-x 4 root root 151 Nov 11 2019 systemd/
drw-rw-r-- 19 root root 4096 Jun 19 18:14 system/
sudo is used to verify that you are the user with which you are logged. you can access root files with your user, but you have to tell your PC that you want to acces files from the root group

file owner can not change ownership in Linux

In Linux, I am the owner of a file, then I tried to change owner to another account, failed. Operation not permitted. Do you know why ? I am the user 'BBB'. Thanks
-bash-4.1$ ls -al
drwxrwxrwx 2 AAA games 4096 Nov 23 14:39 .
drwxr-xr-x 3 AAA games 4096 Nov 23 14:36 ..
-rw-r--r-- 1 BBB esmgroup 16798 Nov 23 14:38 XXX-1.0-SNAPSHOT.jar
-bash-4.1$ chown AAA:games ./*.jar
chown: changing ownership of `./XXX-1.0-SNAPSHOT.jar': Operation not permitted
Only root can change the owner on the file. That's final.
You can do that by login to root using su or use sudo before your command.
More information here: https://unix.stackexchange.com/questions/27350/why-cant-a-normal-user-chown-a-file
You can change the file's group if you're in more than one group.
You should login to root account to be granted to change ownership to any user
You can type sudo before the command and then login to your root user

Deleting a directory as a non-owner of the directory

I have a directory with full permissions with root as owner. What I want is to be able to remove it as a normal user. However, i am not allowed to do so:
radu#Workstation:/tmp$ ls -l | grep cucu
drwxrwxrwx 2 root root 4096 oct 20 10:28 cucu
radu#Workstation:/tmp$ ls -la cucu
total 52
drwxrwxrwx 2 root root 4096 oct 20 10:28 .
drwxrwxrwt 66 root root 45056 oct 20 10:28 ..
radu#Workstation:/tmp$ rm -r cucu
rm: cannot remove 'cucu': Operation not permitted
What do I not get right?
Removing a directory (or a file) consists in deleting its entry into its containing directory, so to remove cucu you need permissions on its parent; alas access rights are rwxrwxrwt, and the t means removal authorized for owner only, as the owner is root, only root can remove cucu.
Sticky bit is set , so only owner can remove the directory.
This is because only root has the permission to remove directory, as you can see
drwxrwxrwx 2 root root 4096 oct 20 10:28 cucu
From your root, change the Permission of directory using chown. For example-
chown radu cucu
Check this out for more info on chown command on linux.
http://www.thegeekstuff.com/2012/06/chown-examples

Can't CD to directory inside of root

I am currently creating an application that requires separate users running duplicate programs. They cannot run under root because of security reasons, so they are initiated by a Java app that I am working on, and I am starting them with runuser -l. However, I cannot cd into a directory, even though it is owned by the user, and the user has 770 permissions in the folder.
Here's what I'm running:
runuser -l lp1 -c 'java \-jar /root/Desktop/workspace/LitePanel/servers/server1/server.jar \-Xms1024M nogui'
And the output of this is:
runuser: warning: cannot change directory to /root/Desktop/workspace/LitePanel/bin/servers/server1/: Permission denied
Here's an ls -all:
drwxr-xr-x. 3 root root 4096 Jan 30 14:03 .
drwxr-xr-x. 7 root root 4096 Jan 30 14:02 ..
drwxrwx---. 2 lp1 lp1 4096 Jan 31 03:07 server1
Inside the directory:
drwxrwx---. 2 lp1 lp1 4096 Jan 31 03:07 .
drwxr-xr-x. 3 root root 4096 Jan 30 14:03 ..
-rwxrwx---. 1 lp1 lp1 9170551 Jan 31 03:07 server.jar
And here's /etc/passwd:
lp1:x:501:501::/root/Desktop/workspace/LitePanel/bin/servers/server1/:/bin/false
Anyone know why this is happening? It looks like the user has the necessary permissions to do this.
You have said that the directory itself has permissions 770 and is owned by the user, but what about its parents? I believe the cd command will need at least read access (and possibly execute) on the parent directories.

how can I control the permissions of files generated by gcc in linux?

The sources for my code all belong to the unix group group1:
> ls -l *c
-rw-r--r-- 1 user1 group1 4976 Nov 9 13:42 commands.c
-rw-r--r-- 1 user1 group1 2347 Nov 9 13:42 env_list.c
-rw-r--r-- 1 user1 group1 2468 Nov 9 13:42 job_list.c
-rw-r--r-- 1 user1 group1 4453 Nov 9 13:42 jobs.c
-rw-r--r-- 1 user1 group1 3278 Nov 9 13:42 smash.c
-rw-r--r-- 1 user1 group1 2151 Nov 9 13:42 variable.c
gcc belongs to group2:
> ls -l gcc
-rwxrwsr-x 1 toolsusr group2 72 Dec 30 2008 /usr/intel/pkgs/gcc/4.3.2/bin//gcc
For some reason, when I compile, all of the targets are marked as belonging to group2. However, when I compile a similar project, the targets remain under group1.
How can I control the group (and while I'm at it, any other permissions) of the generated files?
I am using gcc 4.3.2 and this version of Linux: x86-64_linux_2.6.5_ImageSLES9SP3-3
Take a look at the stick bit of the directory you are compiling in. If set, it will make all of the files written to that directory have the same group of the directory itself. If it is not set, they will have the default group of the user who is writing the file (the user who ran gcc).
You can use
chmod +t dir
to add the sticky bit to a directory.
Comment:
It's not the sticky bit, but rather the setguid bit:
chmod +s dir
gcc doesn't concern itself with ownership of the files. If you need to modify the ownership or permissions of the generated files then you should do so in your makefile.
For user/group updates, put it in your makefile (although it is impossible to change the user unless you are root or you run something like cp as a different user).
For rwx permissions, run uname before running gcc.

Resources