File and Directory Permission
File and Directory Permission
PERMISSION
2023
DO ALAKE
FILE OWNERSHIP
• In Linux, every file and directory is owned by a user and a group. For
example, the files and directories that you create are owned by you
and your primary group. As you will see, such ownership controls
what you and others can do with the files and directories on your
system.
The user and group owner are shown with the ‘ls –l’ command
Group owner
User owner
• You can use whoami command to determine your username. You can
command. The groups command prints a list of the groups you belong
to. The id command prints the same list but includes the GID(group ID
numbers)
The ‘newgrp’ command
• When you create a file, the system assign group ownership to the file based on
your primary group. Lets say you want to create a file that is owned by group
other than your primary group. You use the ‘newgrp’ command to log into that
alternative group. Any files you then created are assigned the alternate group
ID. When done, use the exit command to return to your usual primary group.
Changing file ownership
• You can change the user and group owners of a file or directory by
file then the name of the file or directory. The ‘–R’ option specifies to make
the change recursively. In other words, when you change the ownership of a
directory using the ‘–R’ option, you change the ownership of all of that
directory plus the ownership of all the files and subdirectories it contains
• The ‘chgrp’ command works very similarly, its syntax is
• Only the owner of file or directory may change its user or group ownership. A
practical limitation is this, if you change owner of one of your files to someone else,
you may not change it back. The new owner of the file needs to make the change.
Managing File ownership via command line
COMMAND
1 At the terminal prompt, enter ls -l To view a listing of your files with ownership information
included
2 Enter touch filename (Moneyfile) To create a new file named Moneyfile
3 Enter ls -l The new file is owned by you and your primary group ,
which has the same name as your username.
4 To do this make sure you switch to your root directory That is you want to add a user called rand to your linux.
and add a new user to your linux .using ‘sudo adduser
username’ command
E.G ‘sudo adduser rand’ , press enter and input your
root password
To change the owner of the file called moneyfile to rands
Enter sudo chown rand moneyfile That is to make rands the owner of money file
Enter password (your root password)
Enter ls -l To check if the owner has been changed
5 Enter sudo chgrp new username moneyfile
To make the rands the group owner of moneyfile
At the terminal prompt, enter ls –l : To view a listing of your files with ownership information included
The
moneyfile
has been
created
The owner has been changed from
Dorcas to rand