Linux and Networking

Linux and Networking

3.11 Files has its owner

In every Linux system, the files belong to whoever creates them, who is then the only one who can delete them, execute them, etc. This is so because Unix was designed to be managed by many users at the same time, and in this way no one could access your files without your prior consent.

file attributes
file attributes

 

3.11.1 Changing the owner of a file

 

There are 3 utilities to change the attributes of a file:

 

  • chown Change ownership of the file.
  • chgrp Change group to a file.
  • chmod Changes the attributes of a file.

 

When creating a file, by default, it will belong to the owner who creates it. If I write:

vi saw letter.txt

The letter created will be from Juan Carlos, with its own attributes, but if I am as root, and I create the same letter, the letter will now be root.

 

basic rules

 

  1. Only the owner of a file can change their properties, and even owner.
  2. No user will be able to change the properties of no file, nor its owner
  3. root, you can change the properties of ALL files, and even change their owner.
  4. The above mentioned will be of no use if the group to which it belongs also has the property of writing on the file, therefore, any user can change the owner, group or properties of a file.

 

Examples:

 

To change the owner of a file, you must use the chown command:

chown -c javier ThisFile

Now “ThisFile” will belong to javier.

 

If you want to change the group to the file “ThisFichero”

chgrp –c users ThisFile

 

And if from the beginning you wanted to change users and group have written:

chown –c javier.users ThisFile

 

3.11.1 Changing the attributes of a file

 

  1. chmod u+rwx letter.txt

Where “u” refers to the user who created the file.

 

  1. chmod g+rwx letter.txt

Where “g” refers to the user’s group

 

  1. chmod o+rwx letter.txt

Where “o” refers to the rest of the users. Using “a”, will modify all attributes

 

  1. chmod a+x myscript

It will change all the execution attributes to the “myscript” script, to be run by the owner, the group and others.

 

chmod can also be used with OCTAL numbers. To determine the permissions of a file or

directory the chmod command is used, this command can use two methods to establish them but we will use the simplest called Absolute. It assigns a value to each permission:

 

4 r-read

2 w-write

1 x-run

Exercise:

The Demeter Project