Changing the owner of a file is most commonly used when copying a file to someone else.

Suppose you had a denro.txt file under your Vagrant account:

TXT deniro_copy.txt) to make a copy of this file to someone else:

As you can see, the new deniro_copy.txt file has the owner and ownership group name of Vagrant.

If we give this file to another account, they won’t be able to use it without permission.

One way to solve this problem is to use the CHGRP command to modify group 2 where the new file resides.

Here we take another approach: change the owner of the new file. This uses the chown command. The Linux chown (change owner) command is used to set a file owner and a file associated group.

The format of the chown command is: chown [-r] user[:group] file

  • - RRepresents processing in a recursive manner.
  • User indicates the name of the new owner. The name must be an existing Linux account. The account list is /etc/passwd.
  • File: indicates the name of the file whose owner is to be changed.
  • There is also an option [:group] that allows you to change the group name at once.

For example, if you want to change the owner of the new deniro_copy. TXT file to operator and change the group name to tty, you can run chown operator:tty deniro_copy. TXT.

[1] Bird brother. [M]. The fourth edition. Beijing: Posts and Telecommunications Press, 2018:212-213. 【2】 Talk about how to modify a file group in Linux. 【3】Linux chown command.