Linux Permission
Linux Permission
File permission
The creator of a file becomes the owner of the file and the file also belongs to the creator’s group.
The owner can set permission to file. 3 types of permission
FILES DIRECTORIES
read (r) read and copy list its content
write (w) modify rename, create and delete files
execute(x) run/execute to make as working directory (search and use the files)
Usually you need a read permission as well, to execute certain program for example a shell script (since it is a text file).
To fully protect a file, we need to check both files and directory permission.
chown
To change ownership, you must be superuser or owner
$ chown mamat myfile change ownership of myfile to mamat
$ id to ascertain present user id and group id.
$ id –a additional information on all groups to which the user belongs to
$ ls –l myfile
-rwxr-xr-- 2 mamat staff 155 20 Jan 2:15 myfile
In the above example, myfile is owned by mamat with read, write and execute permission. (-rwxr-xr--)
The members of staff group have read and execute permission only. (-rwxr-xr--)
The rest have read permission only. (-rwxr-xr--)
chmod
To change user permission
$ chmod <usertype> <action> <permission> <filename>
usertype (u =owner, g =group, o =other users, a=everybody)
action (+ add permission, - remove permission, = makes a permission equal to)
permission (r=read, w=write, x=execute)
$ chmod go+w myfile to add write permission to group and other members
$ chmod a+wx myfile to give write and execute permission to all users
$ chmod go-rwx mysub remove all group and other users permission to your subdirectories
umask
umask is opposite of chmod absolute notation table. It denies access. Usually, every users will be issued a default umask for every files created.
$ umask 002 0 users not affected
0 groups not affected
2 write permission for rest of users is invoked.