We can do that using chmod
chmod <permission_for_owner> <per_group> <per_others> filename
Say,We want to give
-rw-rw-r--
==> 4+2 4+2 4
==> 6 6 4
So, the command is
chmod 664 filename
For -rwxrwxrwx ==> 777
To change owner, chown
chown <USER> <FILELIST>
chown root TEST
su - root
We need to sudo (like run as admin in windows) if we set permission.
Similarly, to change group of file:chgrp
chgrp GROUP FILELIST
(or)
chown root:root TEST
Here, first root is owner and second root is group
To set recursively, ownership of all the files -R
To check the file permission, give the following command:
ll file_name
We can use symbols instead of numbers to change permissions.
The following command will add the read/write and execute permissions to the file wherein, u is for user, g is for group, and o is for others:
chmod ugo+rwx file_name
Alternatively, you can use the following command:
chmod +rwx file_name
Default permissions:
can get using umask command.
The o/p will be, say , 0002
The meaning of the preceding output is that, if we create a new directory, then from the permissions of +rwx, the permission 0002 will be subtracted. This means that for a newly created directory, the permissions will be 775 or rwx rwx r-x. For a newly created file, the file permissions will be rw- rw- r--. By default, for any newly created text file, the execute bit will never be set. Therefore, the newly created text file and directory will have different permissions even though the umask is same.
Some more features.
Setuid
Another very interesting functionality is the setuid feature. If the setuid bit is set for a script, then the script will always run with the owner's privileges irrespective of which user is running the script. If the administrator wants to run script written by him by other users, then he can set this bit.
Consider either of the following situations:
$ chmod u+s file_name
$ chmod 4777 file
The file permissions after any of the preceding two commands will be drwsrwxrwx.
Setgid
Similar to setuid, the setgid functionality gives the user the ability to run scripts with group owner's privileges, even if it is executed by any other user.
$ chmod g+s filename
Alternatively, you can use the following command:
$ chmod 2777 filename
File permissions after any of the preceding two commands will be drwxrwsrwtx.
Sticky bit
Sticky bit is a very interesting functionality. Let's say, in the administration department there are 10 users. If one folder has been set with sticky bit, then all other users can copy files to that folder. All users can read the files, but only the owner of the respective file can edit or delete the file. Other user can only read but not edit or modify the files if the sticky bit is set.
$ chmod +t filename
Alternatively, you can use the following command:
$ chmod 1777
File permissions after any of the preceding two commands will be drwxrwxrwt.
chmod <permission_for_owner> <per_group> <per_others> filename
Say,We want to give
-rw-rw-r--
==> 4+2 4+2 4
==> 6 6 4
So, the command is
chmod 664 filename
For -rwxrwxrwx ==> 777
To change owner, chown
chown <USER> <FILELIST>
chown root TEST
su - root
We need to sudo (like run as admin in windows) if we set permission.
Similarly, to change group of file:chgrp
chgrp GROUP FILELIST
(or)
chown root:root TEST
Here, first root is owner and second root is group
To set recursively, ownership of all the files -R
To check the file permission, give the following command:
ll file_name
We can use symbols instead of numbers to change permissions.
The following command will add the read/write and execute permissions to the file wherein, u is for user, g is for group, and o is for others:
chmod ugo+rwx file_name
Alternatively, you can use the following command:
chmod +rwx file_name
Default permissions:
can get using umask command.
The o/p will be, say , 0002
The meaning of the preceding output is that, if we create a new directory, then from the permissions of +rwx, the permission 0002 will be subtracted. This means that for a newly created directory, the permissions will be 775 or rwx rwx r-x. For a newly created file, the file permissions will be rw- rw- r--. By default, for any newly created text file, the execute bit will never be set. Therefore, the newly created text file and directory will have different permissions even though the umask is same.
Some more features.
Setuid
Another very interesting functionality is the setuid feature. If the setuid bit is set for a script, then the script will always run with the owner's privileges irrespective of which user is running the script. If the administrator wants to run script written by him by other users, then he can set this bit.
Consider either of the following situations:
$ chmod u+s file_name
$ chmod 4777 file
The file permissions after any of the preceding two commands will be drwsrwxrwx.
Setgid
Similar to setuid, the setgid functionality gives the user the ability to run scripts with group owner's privileges, even if it is executed by any other user.
$ chmod g+s filename
Alternatively, you can use the following command:
$ chmod 2777 filename
File permissions after any of the preceding two commands will be drwxrwsrwtx.
Sticky bit
Sticky bit is a very interesting functionality. Let's say, in the administration department there are 10 users. If one folder has been set with sticky bit, then all other users can copy files to that folder. All users can read the files, but only the owner of the respective file can edit or delete the file. Other user can only read but not edit or modify the files if the sticky bit is set.
$ chmod +t filename
Alternatively, you can use the following command:
$ chmod 1777
File permissions after any of the preceding two commands will be drwxrwxrwt.
No comments:
Post a Comment