Change file ownership in Ubuntu

In this article, we would cover how to change file ownership in Ubuntu. By default, when we create a file – the user who has created the file has the ownership rights. But, sometimes we want someone else to have the ownership. So, the new owner get the access rights as per file permissions defined.

This can be done through chown command-line utility. It is worth mentioning here that, only the superuser/root can change file ownership. Granting such rights to the superuser restricts other users to make ownership related changes. Reason – not all users are the same.

Note: Following operations would require you to have superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.

Change file ownership in Ubuntu

We will use chown command-line utility. With the help of an example, we will see how to make necessary changes. So, first create a file – test.txt from any user. Open a terminal and issue the following –

touch test.txt

To check who owns the file –

ls -l test.txt

This will return with –

-rw-rw-r-- 1 techpiezo techpiezo 0 May 6 15:56 test.txt

Clearly, it shows that the file belongs to techpiezo user. Now, let’s say we want techp user to own the file now. Therefore, issue the following in terminal –

chown techp test.txt

It will return with –

chown: changing ownership of 'test.txt': Operation not permitted

Because, we can’t change the ownership through a regular user. We need superuser privileges to get the desired outcome.

sudo chown techp test.txt

Do ls -l again –

ls -l test.txt

This time it would return with –

-rw-rw-r-- 1 techp techpiezo 0 May 6 15:58 test.txt

See, the file test.txt still belongs to the same group techpiezo. Now, to make changes to both user and group then,

sudo chown techp:techp test.txt

Check whether both the user and group ownership has changed or not through ls -l command-line utility.

ls -l test.txt

In conclusion, we have discussed how to change file ownership in Ubuntu release.