Linux provides full control over file access which ultimately helps many people to use the system. Files and data are maintained leaving no risks of them being changed, viewed, modified or deleted by any masquerader.
As you might be aware of the three types of users in Linux who may have access to the files:
- User – An account created by the administrator of the system for a user to access that system. Accounts may also be created for machine processes, like the mail, FTP, or web server. Users have direct ownership over files and directories on the system.
- Group – Provides the ability to give access to sets of users. Groups have their own permissions over each file or directory.
- World – Anyone else that may attempt to access a file on the machine.
Three ways in which these types of people can access the file.
- Read – Opening a file and looking at its contents.
- Write – Overwrite, append, or delete a file. In directories, this may include creation of files.
- Execute – The ability to “run” a program (or script).
The “most restrictive access” policy is used for granting any kind of permissions as and when needed. No one has access to anything for no reason.
“chmod” (change mode) is a command for managing permissions.
Basic syntax for this command is:
chmod [who][how to change][permissions to modify] [file or directory name]
The “who” can be:
- u – user or account that owns the file
- g – group that owns the file
- o – others, or “world”, anyone else who may access the file
- a – all of the above
The “how to change” can be:
- = (equals) – set the permissions to exactly what immediately follows
- + (add) – add the permission that immediately follows, leave others as-is
- - (minus) – subtract the permission that immediately follows, leave others as they are
The “permissions to modify” can be, as we’ve discussed:
- r – read
- w – write
- x – execute
Changing Owners and Groups:
Two popular commands exist that can be used for modifying the owning user and group of a file. The first is “chown” (change owner).
The syntax for this is:
chown [user]:[group] [file or directory]
Let’s look at an example:
We have a file called “systems.lst”. We need to change its owner to a user called xyz who is in the abc group:
chown xyz:abc systems.lst
Anyone intending to change the group, can use another command, called “chgrp” (change group”.
The syntax for this command is:
chgrp [group name] [file or directory name]
Here is an example:
There is a file called “run.sh” that we want to change to be owned by the abc group:
chgrp abc run.sh
Other Linux Commands:
- useradd – add a system user
- userdel – remove a system user
- usermod – modify an existing system user. This can be used to perform several operations on a user’s account.
- groupadd – add a group to the system
- groupdel – remove a group from the system
- groupmod – modify a group
We hope sharing this Linux Tutorial will indeed be useful to you, don’t forget to re share it.