Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to change ownership of files and directories in Linux

📅 2014-May-09 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ chown ⬩ 📚 Archive

You typically get access permission errors when you try to access files and directories created by a different user. The chown command can be used to change the ownership of files and directories in Linux. If you are changing the ownership from user1 to user2, you need to have permissions that are higher than these users. So, typically these commands are performed using sudo.

To set owner of a file or directory:

$ chown foouser blah.txt
$ chown foouser blahdir

To set group of a file or directory:

$ chown :somegroup blah.txt
$ chown :somegroup blahdir

To set both user and group:

$ chown foouser:somegroup blah.txt
$ chown foouser:somegroup blahdir

To set ownership recursively on all files and subdirectories in a directory:

$ chown -R foouser blahdir
$ chown -R :somegroup blahdir
$ chown -R foouser:somegroup blahdir

If you prefer using a GUI for changing ownership, you can do that in any file explorer. For example, in Nautilus just right-click on the file or directory and choose Properties > Permissions. Note that you need to be the root user or have launched Nautilus using superuser permissions to be able to do this.

Tried with: Ubuntu 14.04