| by Scott Kilroy | No comments

How to manage ownership of files in linux

In Linux operating system, there are three types of owners;

  1. User: A user is the one who created the file. By default, whosoever, creates the file becomes the owner of the file. A user can create, delete, or modify the file.
  2. Group: A group can contain multiple users. All the users belonging to a group have same access permission for a file.
  3. Other: Any one who has access to the file other than user and group comes in the category of other. Other has neither created the file nor is a group member.

In this guide, we will see how to achieve basic file security through file ownership in our Linux system

user owner and group owner

The users and groups of a system can be locally managed in /etc/passwd and /etc/group, or they can be in a NIS, LDAP, or Samba domain. These users and groups can own files. Actually, every file has a user owner and a group owner, as can be seen in the following screenshot.

In here, the root user own 2 files.

listing user accounts

You can use the following command to list all local user accounts.

#cut -d: -f1 /etc/passwd | column

chgrp

You can change the group owner of a file using the chgrp command.

#chgrp <group name> <filename>

chown

The user owner of a file can be changed with chown command.

#chown <user> <filename>

You can also use chown to change both the user owner and the group owner.

#chown <user>:<group name> <filename>

list of special files

When you use ls -l, for each file you can see ten characters before the user and group owner. The first character tells us the type of file. Regular files get a , directories get a d, symbolic links are shown with an l, pipes get a p, character devices a c, block devices a b, and sockets an s.

Below a screenshot of a character device (the console) and a block device (the hard disk).

And here you can see a directory and a regular file.

 

The post How to manage ownership of files in linux appeared first on The Linux Juggernaut.

Share Button

Source: The Linux Juggernaut

Leave a Reply