Permissions Exercises (1)
Permissions Exercises (1)
$ cd
$ echo “test file” > working.txt
$ chmod 444 working.txt
$ ls -lh working.txt
In spite of the fact that the file does not have write permission for the owner, the owner can still
change the file’s permissions so that they can make it possible to write to it.
To remove the read permission for the user on a file you would do
$ cat working.txt
What happened? You can’t read your file. Make the file again readable by you by completing the
following command (replace ???)
$ groups
user_name adm dialout cdrom floppy sudo audio dip video plugdev netdev
Let’s add our user to the team group - the ‘-a’ is important!
You won’t be able to use your new group until you have logged in and out from your account, or
have simulated this process by doing this:
$ su - user_name
$ groups
user_name adm dialout cdrom floppy sudo audio dip video plugdev netdev team
Do the following:
$ cd
$ echo “This is our group test file” > group.txt
$ chgrp team group.txt
$ ls -l group.txt
How would you give members of the group team read/write access to this file? Before you look
below try solving this on your own.
We’ll use the numeric chmod functionality.
$ ls -l group.txt
$ cd
$ touch hello
NOTE: you can use file editors to edit the file. Besides, you can add any other sequence of
commands to this file.
$ ./hello
This implies that the file is not executable. We need to set the file’s permission to be executable
by our user. How would you do this?
$ ./hello
On your screen, you should see …
Hello, world
Now set your hello file to be readable by everyone, NOT executable by you, and executable by
the Group and by Other.
$ ls -l hello
There are several ways you can do this with the chmod command.
Once you have set the permissions like this, what happens if you now type?
$ ./hello
Why does this happen? If you execute the file as a different user it will still work! Does this seem
odd? (Hint: think “left to right”)
$ sudo ./hello
Now set the file back so that you can execute it. Verify that this works.