In: Computer Science
What chmod command would you use to impose the following
permissions?
1. on a directory(called dir1) and all its subdirectories such
that: the owner would have read, write, and execute; the group
would have read and execute; and others would have read(write the
command in two ways: using rwx and using numeric value)
2. on file (called file1)such that: the owner would have read and
write; the group would have no permissions; and others would have
write
(write the command in two ways: using rwx and using numeric value)
3. set the special permission SGID and sticky bit for dir1.(you don't need to change the defined permission in 1)
Starting from the Linux default permissions for file and
directories, what umask command would you use to ensure that for
all new:
4. directories, the owner would have read, write, and execute;
members of the group would have read and execute; and others would
have read
5. files, the owner would have read and execute; the group would
have read, write, and execute; and others would have execute
Please like the answer if you find it satisfying or please leave a comment i will repy to it.
1)
what you really want to do is set the directories to 755 and
either leave the files alone or set them to 644. For this, you can
use the find
command. For example:
To change all the directories to 755
(drwxr-xr-x
):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--
):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
2) chmod 640 file1, which means that the owner has read and write permissions, the group has read permissions, and all other user have no rights to the file.
to set a file to permissions on file1 to read _rwxr_____, you would enter chmod 740 file1.
3)
When the SGID
bit is set on an executable file, the
effective group is set to the group of the file. The process runs
with the permissions of the members of the file’s group, rather
than the permissions of the person who launched it.
sudo chown root:mary /usr/local/bin/htg
sudo chmod u-s,g+s /usr/local/bin/htg
ls -lh /usr/local/bin/htg
You can see the SGID
bit denoted by the “s” in the
group permissions.
The Sticky Bit
When you set the sticky bit on a directory, people can only delete files that belong to them within that directory. They can’t delete files that belong to someone else, no matter which combination of file permissions are set on the files.
mkdir shared
sudo chmod o+t shared
ls -lh -d shared
ls -lh -d /tmp
ls -lh -d /var/tmp