how can I control the permissions of files generated by gcc in linux? - 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.

Related

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

How to change ubuntu to root?

I am new to linux. when i list the files under folder 1, i see below result
-rwxrwxrwx 1 root root 920 Jun 3 10:36 file1.xsd
-rwxrwxrwx 1 root root 920 Jun 3 10:36 file2.xsd
drwxrwxrwx 2 ubuntu ubuntu 4096 Jun 12 11:10 temp
-rwxrwxrwx 1 ubuntu ubuntu 1853 Jun 19 11:07 file3.xsd
for some files(file1 and file2) root root is written after permisionsbut for file3 ubuntu ubuntu is displayed.
what is difference b/w ubuntu ubuntu and root root ?
How can i change ubuntu ubuntu for file 3 to root root ?
The first "root" stands for user name and second "root" stands for the group name. By design, Ubuntu uses "sudo" command to run other commands "as root", and the actual root user is not used.
So what that means, every time you use the command sudo to run a command, it is actually being done as root. That's most likely the reason for the two of your files being owned by root (and the group root).
You can change the ownership of the file with command chown:
chown root:root file3.xsd

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.

Change user and group of files

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

linux permission group

I am trying to setup my webserver so that one group will have access to the files. Apache and every user that needs to edit the files will be part of this group. So I've set all the files to have the group psacln. I've added psacln to my groups. But it still won't let me view the files:
[tom#166 httpdocs]$ whoami
tom
[tom#166 httpdocs]$ groups tom
tom : tom adm wheel apache psacln andy
[tom#166 httpdocs]$ ls -al
ls: .: Permission denied
[tom#166 httpdocs]$ sudo ls -al
total 92
d---rwx--- 14 andy psacln 4096 Jul 22 17:51 .
drwxrwxr-x 16 apache apache 4096 Jul 21 09:29 ..
d---rwx--- 4 andy psacln 4096 Jul 21 09:26 backend
d---rwx--- 3 andy psacln 4096 Jul 22 15:21 core
d---rwx--- 5 andy psacln 4096 Jul 21 09:26 css
...
One thing that may be useful to note, is that when you change a user's group membership, you will have to log out and back in again (i.e. group memberships will take effect when you log in and don't normally change otherwise).
You can either log in and out to let the group change take effect, or changing your "active" group with the newgrp command will also do this for you.

Resources