Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When could or should I use chmod g+s on a file or directory?

Tags:

unix

sysadmin

In deploying to a new (Solaris 9) environment recently, one of the steps was to copy a set of files and directories to their new location and then to apply the group UID bit (using "chmod -R g+s") to all files in the directory tree giving a mode of -rwxr-s--- to everything. The result was that none of our shell scripts would execute unless they were individually opened and re-saved. I should add that we had earlier set g+s on the target parent folder prior to copying files; this had set the initial mode on all the new directories to drwxr-s--- but the files had a mode of -rwxr-x---

Having eventually discovered which step caused the problem, we were able to cut out that step and proceed.

I would like, however, to understand what the "s" bit means when applied to directories and files, in the hope that this will explain why we had the problem in the first place.

like image 387
Jordanhillbilly Avatar asked Oct 10 '08 12:10

Jordanhillbilly


People also ask

What does chmod gs do?

This command sets the "set group ID" (setgid) mode bit on the current directory, written as . . This means that all new files and subdirectories created within the current directory inherit the group ID of the directory, rather than the primary group ID of the user who created the file.

Can you use chmod on a directory?

To modify the permission flags on existing files and directories, use the chmod command ("change mode"). It can be used for individual files or it can be run recursively with the -R option to change permissions for all of the subdirectories and files within a directory.

What is the difference between the W permission for a file and for a directory?

Read permission on a directory implies the ability to list all the files in the directory. write (w) Write permission implies the ability to change the contents of the file (for a file) or create new files in the directory (for a directory).

Why would you want to run chmod on a file?

chown (or “change owner”) dictates who owns a file. Specifically, chown controls what user and what group owns a given file or set of files. Worded differently: If you want to change what users can do with a file, you probably want chmod.


1 Answers

Setting directories g+s makes all new files created in said directory have their group set to the directory's group.

This can actually be really handy for collaborative purposes if you have the umask set so that files have group write by default.

Note: This is the way it works in Linux, it could work completely differently in Solaris.

like image 68
Powerlord Avatar answered Sep 21 '22 09:09

Powerlord