Day 2:
File permissions, modifying file permissions
In Linux there are many users can work on single system. There are different kinds of users having certain work allocating to them and access on same system. In this case, we want give access of specific users to a specific files,we need a permission for particular user for particular files.
So these permission are mainly into three types that are read, write , execute .We can see these permission by ls command.ls commands list all files and directories containing in particular directory.If we want list the permission just type ls – l command.The output will be as shown below.
$ ls -l /data
-rw-r–r– 1 bob users 10400 Sep 27 08:52 F1
-rw-r–rw- 1 bob users 10400 Sep 27 08:52 F2
drw-rw-r– 1 bob users 10400 Sep 27 08:52 data1
Here we can see that ls command displays all directories and files containing in data directory. – denotes the regular file ,d denotes at the beginning of line is directory,l denotes the symbolic link.We can also the symbolic notation of permission by single letter that are r for read,w for write and o for others.They also explained their self explanatory that is if you have read permission then you see the all contents in particular file or files that are accessible to particular user. If you have write permission then you can read as well as write the contents or modify a particular file.If you execute permission then you run the files that are accessible to you.
In above example shown we can see here is that the permissions are followed for three different types of users.These categories are first for user,then group user and followed by other user. The permissions for first user is the owner of that files .It means that the user created or owned by that file. Second the permission for group user which is part of any group. Last is the permissions for other user that is other than owner and group user which is not belong to any group.
The user who owns the file is represented by u, the users that are in the file’s group are represented by g, and the other users who do not own the file or are not in the file’s group are represented by o. The character a represents all, meaning user, group, and other. Also a denotes the for all users. Even though these characters do not show up in an ls listing, they can be used to change permissions.
Changing permission by chmod:
The file permissions can be knows as modes,that the command is called chmod . As discussed above we ugoa symbols for changing permission and used + to add permission,- to substract the permissions and = to set explicitly . Basic syntax for chmod command is as follows,
$chmod permissions filename
For example,
$chmoad u+w data1
Here we changed the owner permission and give him write for file modification.
Numeric Based Permission:
We can give permission based on number. Above learn symbolic permission may help you to learn octal mode of commands. But in this case you can easily remember the permissions because of numbers. Here are numbers to represent the permissions which are converted from octal to binary and then binary numbers.
There are shortcuts for it ,that we can remember 4 equals to read,2 equals to write and 1 equals to execute.Futher permission made by combination of these numbers. One big advantage of this mode is we can set permission for user ,group user and other at the same time .But in symbolic permission we can set permission one at a time.
Some default used permission as shown below
700- files can only be read , write and execute by owner.
755- files read ,write and execute by owner,read and execute by group and other user.
664 – files can read and write by owner and group user and only read by other user.
644 – files can allow owner to read and write,group user and po other only read files.
In this way we have learn about file permissions and it’s changing permission.
In next topic you will learn about creating and editing files and managing users by adding into group…..