Today we are going to discuss about one more useful command which will be very important in security aspect i.e. When ever you have file/folder which is very important and you don't want others to read your content then this post is very very helpful in making your content private.
chmod is a command by which you can modify permission of a file/folder according to your wish.
chmod -R 777 /home/x/y.java
Above command will give permissions to read, write and execute for the file 'y.java' present in path '/home/x' so that 'y.java' can be accessed (read, write and execute) by anyone.
In the above command main important part is 3 '7's which decide up to what level one can access corresponding file.
First digit: First '7' is used to give permissions to corresponding user. And one can assign '0-7' We can discuss what is the meaning of each digit from '0-7'.
Second digit: Second '7'is used to give permissions to group to which corresponding user belongs too. And one can assign '0-7' for this digit too.
Third digit: Third '7'is used to give permissions to others. Similar to above 2 digits one can assign '0-7' for this digit too. And you can also refer previous post which contains same explanation.
Regarding assigning '0-7' to each user/group/others please read below table for clear explanation.
# | Permission | rwx |
---|---|---|
7 | full | 111 |
6 | read and write | 110 |
5 | read and execute | 101 |
4 | read only | 100 |
3 | write and execute | 011 |
2 | write only | 010 |
1 | execute only | 001 |
0 | none | 000 |
So, as per above table if you don't want to give neither of read,write and execute permission to user, group and others then you can use '000' to assign permissions to corresponding file.
chmod -R 700 /home/x/y.java
Yes, as per your guess, above command will give read,write and execute permission to user and gives no permission to group and others. So, that we can restrict 'y.java' file to corresponding user only.
Like this you can use different combinations in the above table to give/restrict permissions to corresponding user, group and others.
One more important point to remember to use this command is, file to which you are going to modify permissions should be closed and you should be owner of the file. You can also get more information about this command by hitting 'man chmod' in the terminal.
Please feel free to post any help/suggestion. Will discuss some more in next posts.....
No comments:
Post a Comment