The linux admin inadvertently changed permissions on /usr/bin/ls, a 64-bit ELF executable, from 755 to 511. Which users are now authorized to execute "ls" from the command line?
- Only the owner and members of the group associated with the file.
- User root, and only user root.
- All users.
- The owner, and only the owner.
EXPLANATION
How to change your file to 511 or -r-x--x--x using chmod
Chmod is a well known command line utility, that's used to manage file permissions on MacOS, Linux and other Unix like operating systems. While there are multiple ways to use chmod, on this site, we have chosen to focus exclusively on using chmod with Octal Notation. The following examples illustrate exactly how to change your desired file to permissions matching "511 or -r-x--x--x" using the command line and chmod. If you're lost on how to manually manage file permissions, see our guide - How Do I Change File Permissions Using chmod?From your terminal run the following command, within a directory containing the file you wish to change permissions on. In this case the filename is "yourfile.txt"
$ chmod 511 yourfile.txt
Confirming your change, your file's symbolic permissions should now be "-r-x--x--x"
$ ls -l
# your output will be similar to the following
-r-x--x--x 14 root root 4096 Jun 22 07:36 yourfile.txt
# your output will be similar to the following
-r-x--x--x 14 root root 4096 Jun 22 07:36 yourfile.txt
/usr/bin/ls is an ELF 64-bit executable and "r"ead access in not required by the kernel to execute it.
$ ## Determine the current user, group, and supplementary groups $ id uid=1001(terry) gid=100(users) groups=100(users),600(ftpaccess),601(terry),1001(mktg),1002(acctg),1004(family) $ ## Determine the file type of /usr/bin/ls $ file /usr/bin/ls /usr/bin/ls: executable, regular file, no read permission $ ## Show the permissions, owner, group of /usr/bin/ls $ ls -l /usr/bin/ls -r-x--x--x 1 root root 110272 Mar 17 2014 /usr/bin/ls $ ## Try to run the ls command as user terry, group users $ ls -l /tmp/Test total 12 drwxr-xr-x 3 root root 4096 Aug 11 2015 a -rw-r--r-- 1 root root 8003 Feb 22 2016 known_hostsNote that if a file is a shell script, read permission is required, in addition to execute, because the user's shell must be able to read a script in order to run it. This is not the case with binary executable files, where only the "x" bit needs set.
Aside: In the case of a shell script, a script file with read, but not execute permission, can be passed to the shell as an argument to be run, eg. "bash script.sh"
See "Execute Permission of a file" at http://www.grymoire.com/Unix/Permissions.html#TOC
0 comments:
Post a Comment