Shell Permissions.

Shell Permissions.

change users, id, and accessibility of the file.

·

3 min read

Unix operating systems and its successors, (such as the GNU/Linux system), are not only multitasking systems, they are also multiuser systems. As such the way files are held, and the permissions they hold are a bit different from windows files. Files usually have an owner, and different users and/or groups can do limited tings with a particular file. To see the various permissions and owners of a file in a particular directory, list the files in long format.

For a detailed explanation on the binary representation of file permissions and ownerships read this brilliant section. this article will see how to manipulate the permissions and users.

Changing Users

Since the system itself has several users, one can change to a different user, with different permissions using the su command. For example to change to the user betty, run su betty.

To get the name of the current user, i.e. your username as you are logged in, use the whoami command.The groups command will print the names of the current groups the current user is a part of.

To change the owner of a file, use the chown command. Its syntax is chown -option owner file . The man pages, man chown, give more information on manipulating this command.

Files

To create an empty file, use the touch command. e.g. touch filename. The touch command creates an empty file without opening it or appending anything to it unlike other commands.

To add permissions to a file use the chmod user+permission syntax with the chmod command. e.g. to add execute permission to the owner of file hello, chmod u+x hello . Now adding a permission does not reset the other permissions but simply gives the specified user new access without bothering the permissions of the other users. The above example assumes the file is in the working directory. f it is not, specify the path to the file.

To set the permissions, overwriting previous permissions manipulate the chmod command using binary setting in this page. To set the permission to the file hello as follows:

  • Owner: no permission at all

  • Group: no permission at all

  • Other users: all the permissions

use chmod 007 hello. To set the permissions of a file to be like another file use the --reference flag. chmod --reference=pathtofiletobecopied filetosetpermissionsasformerfile . Of course, wildcards can still be used. e.g. To add execute permission to all subdirectories of the current directory for the owner, the group owner and all other users: chmod ugo+X * .

To create a directory with given permissions use the mkdir with the -m option. e.g. To create a directory called my_dir with permissions 751 in the working directory: mkdir -m 751 my_dir .

To change the group owner, use the chgrp command. e.g. To changes the group owner to school for the file hello: chgrp school hello . man chgrp to learn more.

To change the owner and group owner using the chown command specify the onwer and group separated by a colon.

To change the ownership of symbolic links use the -h flag with the chown command.

To change ownership from one user to another use the --from=previousowner option. Of course, replacing previous owner with the name of the previous owner.