LINUX
LINUX : CHAPTER 7 USERS, GROUPS AND PERMISSIONS
USERS
During the early days of computing, computers are very large and expensive.
The concept of users was created to allow many individuals to share these precious computing resources. Every person that logs into the computer is consider a user.
GROUPS
Each user belongs to one or more groups. A group is a set of users who are alike in some way. For example -
The group name student might contains all users who are students.
Users when created are assigned to one or more groups by the system administrator. Each group have appropriate group permission set for files or directories.
The WHOAMI command display the current user and the groups command display the users group.
PERMISSIONS
Linux is a multi-user os that is more than one user can work on a Linux system at the same time.
Linux provides a mechanism known as file permissions, which protect a users file permissions, which protect a users file by other users. This mechanism lets files & directories re-owned by a particular user.
PERMISSION TYPES
Files & Directories permissions fall into three main divisions -
1. Read Permission (R)
2. Write Permissions (W)
3. Execute Permission (X)
EXAMINE PERMISSIONS
The LS command with the -l option display a long listing of the file attributes.
$ ls -l
CHANGING FILE OWNERSHIP
File ownership can be changed with the chown command. For example -
To grant ownership of the file "My file" to Student, the following command could be used
$ chown student my file
CHANGING PERMISSIONS
Typically users on a Unix System are open with the files. The usual set of permissions given to file is rw - r -- r --, which leads other users read the file but not change it in any way.
The usual set of permission given to directories is rwx - r - rr - x, which leads other users look through you directories, but not create or delete files within them.
The usual set of permission given to directories is rwx - r - rr - x, which leads other users look through you directories, but not create or delete files within them.
CHANGING PERMISSION-SYMBOLIC METHODS
In order to change the default permission and set your own permissions, chmod command is used.
Only the owner of the file can change the permission on that file.
The Syntax of chmod command -
$ chmod category operation permission file-name
In the first argument you supply one or more of all, owner, group and others. Then you specify whether you are adding or taking them away.
Finally you specify one or more of read, write and execute permissions -
Example
$ chmod g +w myfile
$ chmod g =r myfile
Example
$ chmod g +w myfile
$ chmod g =r myfile
CHANGING PERMISSION-NUMERIC METHODS
Instead of the character arguments, one can give numeric argument to the chmod command.
The notation takes the form of an octal representation of the permission and it is assign like the following -
When more than one permission is associated with a particular user class, the respective numbers are added.
For example
r-- r-- r-- chmod 444 filename
rw-rw-rw- chmod 666 filename
rwx rw- --x chmod 761 filename
STICKY BIT
We can add sticky bit to a directory to prevent the files within it from getting deleted.
With the sticky bit to a file, no one except the owner of the directory and the root user, can delete files from this directory.
To add the sticky bit to a directory give the following command -
$ chmod u + t north
FILE OWNERSHIP
When a file is created, the created file is become the owner of the file and the group to which the owner belongs becomes the group owner.
CHANGING FILE OWNERSHIP
Their are two commands that can be use to change the ownership of a file or directory.
1. chown (change ownership)
This command is use to grant the ownership of a file to another user.
for example-
chown statish aman
where
chgrp : command
statish : new owner
staff : file name
2. chgrp (change group)
The command chgrp changes the group ownership of the file. This command like chown can only be used by the owner of the file.
for example-
chgrp faculty aman
where
chgrp : command
faculty : new group
staff : file name
When a file or directory is file created, the file permissions are set rw-rw-rw (666) and directory permissions are set to rwxrwxrwx (777).
The value of variable umask is subtracted from these default values. By default, the value of umask is 022.
Hence when you create a new file, the default permission is 644 (666-022) which is rw-r--r--, and the default directory, permission is 755 (777-022) which is rwxr-xr-x.
Note that the permission is set to rw-r--r--, Then we changed the value of umask variable using this command ;
$ umask 044
From now on all new files and directories will have their default permissions transformed by subtracting 044 from it.
DEFAULT FILE PERMISSION - UMASK
Unix system uses a variable called "umask" to decide on the default file and directory permissions.When a file or directory is file created, the file permissions are set rw-rw-rw (666) and directory permissions are set to rwxrwxrwx (777).
The value of variable umask is subtracted from these default values. By default, the value of umask is 022.
Hence when you create a new file, the default permission is 644 (666-022) which is rw-r--r--, and the default directory, permission is 755 (777-022) which is rwxr-xr-x.
Note that the permission is set to rw-r--r--, Then we changed the value of umask variable using this command ;
$ umask 044
From now on all new files and directories will have their default permissions transformed by subtracting 044 from it.
Your feedback is very important for us :)

Post a Comment
0 Comments