In: Computer Science
Create by using Linux server
• Create a file name it foo.txt
• Remove all permissions from foo.txt
• What happen if you try to read the file?
• Change foo.txt permission to read and write only for owner
• Change foo.txt permission to read for group
• Change foo.txt permission to read and write everyone
1) Create a file name it foo.txt
Solution :
vi foo.txt
press i for input mode in linux and write the content and then save it with :wq!
ls -l (to see the permission of files in the current directory)
total 8
-rw-r--r-- 1 runner runner 13 Oct 14 04:46 foo.txt
-rw-r--r-- 1 runner runner 31 Oct 14 04:46 main.sh
2) Remove all permissions from foo.txt
It can be done with chmod option and remove all permissions of owner group and others with 000 respectively.
chmod 000 foo.txt
ls -l
total 8
---------- 1 runner runner 13 Oct 14 04:46 foo.txt
-rw-r--r-- 1 runner runner 31 Oct 14 04:46 main.sh
3) What happen if you try to read the file?
It will be showing permissioned denied because its permission to read has been revoked.
cat foo.txt
cat: foo.txt: Permission denied
4) Change foo.txt permission to read and write only for owner
chmod 600 foo.txt
ls -l
total 8
-rw------- 1 runner runner 13 Oct 14 04:46 foo.txt
-rw-r--r-- 1 runner runner 31 Oct 14 04:46 main.sh
5) Change foo.txt permission to read for group
chmod 640 foo.txt
ls -l
total 8
-rw-r----- 1 runner runner 13 Oct 14 04:46 foo.txt
-rw-r--r-- 1 runner runner 31 Oct 14 04:46 main.sh
6) Change foo.txt permission to read and write everyone
chmod 646 foo.txt
ls -l
total 8
-rw-r--rw- 1 runner runner 13 Oct 14 04:46 foo.txt
-rw-r--r-- 1 runner runner 31 Oct 14 04:46 main.sh