Wednesday, 29 July 2015

DAY 2

Hello! Its DAY 2

I left with permissions last night.

I opened the terminal. In ubuntu when i open the terminal it always open it as normal user not super user. i tried many times to open it as Super user with the  su command but it never worked may be later i will find a solution for it.
But in search for that i found an alternative its sudo -i command.

type this command then enter your password and it will login to super user.


sumit@sumit-HCL-Notebook:~$ sudo -i
[sudo] password for sumit:



Why do i need to log in as a super user ??

The simplest answer is the super user can do anything it has all the privileges.
A normal user can't to everything
eg. normal user can not add more users or change permissions of users and group .


Now coming back to the point.

PERMISSIONS :

there are four permissions in Linux or almost in any OS

  1. Read
  2. Write
  3. Execute
  4. no permissions

we already know how to check permissions of a given file or of all the files in a given directory by using ls -l command.

root@sumit-HCL-Notebook:~# cd /home/sumit/Desktop/linux_journey/
root@sumit-HCL-Notebook:/home/sumit/Desktop/linux_journey# ls -l
total 0
-rw-rw-r-- 1 sumit sumit 0 Jul 29 04:37 Day1.txt  


Here, I first changed my directory and came to the directory which i created for the practice and then checked the permissions of the files in folder.

This Image will help you understand what is all this -rw-rw-r-- 


There is one more thing you should know about it and which is very very Important to know that how we give this permission and the concept of this.
  
 these are the values associated with r w x & -

r  = 2^2   = 4
w =2^1   = 2
x  =2^0   = 1
-   =0        = 0

How to use it ?

as you can see there are four parts in permissions list.
first - indicates file type.
second --- permissions for owner.
third --- permissions for group.
fourth --- permissions for others.


before we go further first understand what is owner, group & others.

Owner : is the super user
Group : is the group of some users. so if we apply any permission on the      group        it    will automatically apply on the users of that group.
Others : these are the users which are not in any group or you can say are individual not related to anyone.


Giving permission

while giving permission we don't have to care about file type now.

the command is

chmod 754 <file name>

here chmod is the command used for applying permission

now 754 is going to tell us that what are the permissions on different users and group.

7 as you can see it is the sum of 4+2+1 which is r+w+x  and it is for owner.
so the owner now have full permission on the given file.
5 = 4+1 which is r+x and it is for group.
so the group can only read and execute the file.
4 = 4 only . which is r and it is for others
so others can only read the file.

you can set any permission as you want you just have to take care of the numbers associated with permissions.

Now, lets see our file which we have created yesterday

root@sumit-HCL-Notebook:/home/sumit/Desktop/linux_journey# ls -l
total 0
-rw-rw-r-- 1 sumit sumit 0 Jul 29 04:37 Day1.txt


it is having read and write for both owner and group . only read for others.

now i want to give full permissions to all of them .

root@sumit-HCL-Notebook:/home/sumit/Desktop/linux_journey# chmod 777 Day1.txt
root@sumit-HCL-Notebook:/home/sumit/Desktop/linux_journey# ls -l
total 0
-rwxrwxrwx 1 sumit sumit 0 Jul 29 04:37 Day1.txt







and its done. Now everyone is having full permission on this file.


 its time to go ..  BYE ;)

 


 

No comments:

Post a Comment