Linux or Unix security features are creative indeed. Linux or Unix system have three types of owner.
User : The User is the one who created the file. Default system is, whosoever, creates the file becomes the owner of the file. Every user can create, delete, or modify the file.
Group : Linux group can contain multiple users. Every users belonging to a group have same access permission for a file.
Other : Any body who has access to the file other than user and group comes in the category of other. The Other has neither created the file nor is a group member.
The Linux or Unix Users and groups can be locally managed in /etc/psswd and /etc/group. However, you should always user the command line tools to manage users or groups.
Lets see a list of files using
The first column like
drwr-xr-x is the permission tag line for the file. The second column is the owner of the file and the third column is the group to which the file belongs to.
Listing User Accounts
To list The local users, following command can be used. This will list all the local users from the system.
# cut -d: -f1 /etc/passwd | column
Linux chgrp command
chgrp command can be abbreviated as change group. You can change the group owner of a file using chgrp command.
$ chgrp <group-name> <file-name>
$ chgrp root test.txt
After running the command do a
ls -lh, notice that the owner group of the file has been changed
Note : Only root user have the permission to change the owner or group of the files in the system.
Linux chown : change owner
Command chown is used to change the owner of the file.
$ chown <username> <filename>
$ chown test2 list
Command chown can also be used to change both user owner and group.
$ chown <username:group-name> <filename>
$ chown root:ubuntu msg.txt
List of Special Files
If you type ls -l command, ten characters are display before user owner and group. It may be like
The first character tells us about the type of the file.
Following are the file types:
– Normal file
l Symbolic link
p Named pipe
b Blocked device
c Character device
There are three types of basic permissions for any file: read, write, execute.
Letters used to denote permissions are:
- r – Read
- w – Write
- x – Execute
Lets consider a example tagline for a file:
The first letter signifies the type of the file as we described earlier.
The the first set of permissions rwx is the permission set to owner.
The second set of permissions r-x is the permission set to group. We can see that the group can not write to the file. But can execute that.
The third set of permissions r-x is the permission set to every other user in the system. So, we can see that, any user in the system can read and execute the file, but can’t write to it.