As a person whose devices only pass through their hands (and be careful not to touch them), things like having multiple users on the same computer or working with shared folders sounds like something that only happens in movies to me. But no, it also happens in real life, and it can even happen that we ourselves want to make changes like change the owner of a folder in linux… although the owner will later also be us.
It may be for whatever reason, but changing the owner of a folder in Linux is a task that can be common and is performed to ensure that only authorized persons have access to the files and folders in question. Here is the detailed process to change the owner of a folder in Linux.
Table of Contents
Change folder owner from terminal
Although some people may respect the terminal, many things in Linux are better done with command lines. The process to follow to change the owner of a folder in Linux would look like this:
- We open a terminal. In many distributions, it is achieved by pressing Ctrl + Alt + T. If we press that combination and it does not appear, we can look for it in the applications menu.
- In the next step, what we have to do is to identify the current owner of the folder. This can be done with the command "ls -l folder-name" without the quotes and replacing "folder-name" with the actual folder name, path included if necessary. For example, if the folder is my-tests, the command would be:
ls -s my-tests
- This command will display detailed information about the "my-tests" folder, including the current owner. If it has no owner, the above command will return "total 0".
- Next, the "chown" command will be used to change the owner of the folder. It is important to mention that only users with administrator permissions can use the "chown" command to change the owner of a folder. If we try to change the owner of a folder and see an error message, we probably don't have the necessary permissions. Knowing the current owner, and being the root user, the command to change the owner would look like this, logically using the name of the new owner and the name of the folder in question, in this example, my-tests:
chown new-owner my-evidence
- Next we would check that the owner of the folder has indeed changed, for which we will use the same command as in step 2. If everything went well, the name of the owner will be different from the one we saw before starting the process .
Change the owner of multiple folders at once
It is worth mentioning that the "chown" command can also be used to change the owner of several folders at the same time, or in other words, it can be used to make batch owner changes. To do this, simply specify several folder names after the new owner. For example:
chown new-owner my-tests1 my-tests2 my-tests3 my-tests4
This command will change the owner of the "my-tests1", "my-tests2", "my-tests3", "my-tests4" folders from the original owner to new-owner.
Another option is to use a wildcard (*) to change the owner of all folders within a specific directory. For example:
chown -R user2 /directory/*
The above command will change the owner of all folders within the "/directory" directory from the original owner to "user2".
Using file managers
"And why didn't you start here?" some of you may ask. Well, it was an option. He rides so much, he rides so much. partly because commands are more reliable than graphical tools, or usually are, and partly because these GUI options are easier to find. But you have to know that you can also change the owner of a folder with file managers, such as Nautilus or Dolphin. I speak of these two examples because they are the most popular and the ones that use GNOME and KDE, but it can be done in others as well.
- Right click on the folder to which we want to change the owner:
- We click on Properties.
- We click on Permissions.
- Finally, we click on the name of the owner (it puts “Owner” under the arrow…) and we choose the new owner. It will ask us for the password, and we will only have to put it on.
In Dolphin, the process is very similar:
- We right click on the folder and choose the “Properties” tab.
- In the new window that opens, select the "Permissions" tab.
- Next, click on “Advanced Permissions”, and from there we can find the new user and assign them ownership of the folder. As in Nautilus, you will have to confirm the changes by entering the administrator password.
Something to take into account: if someone is trying to test what is described here with Nautilus, Dolphin or another manager that offers this possibility and does not see the different users, one thing must be known, that logically it may seem that it never hurts to provide information. And it is that the last steps will only be possible if there is more than one user registered on the computer. Otherwise, since there is no one to give the folder to, nothing will come of it.
If someone insists on continuing to the end, which may be to learn the process in case it is needed in the future, before starting with the steps to change the owner of the folder, you have to create a new user, just like I did with the user "ubunlog". To do this, just go to the operating system settings, search for users and create a new user. For the folders to appear, the user will likely need to log in at least once. When it has been verified that everything works as stated here, you can go back to the settings and delete the user, as long as the user has closed the session.
In conclusion, changing the owner of a folder in Linux is an important task that can help ensure the security and privacy of the files and folders in question. Using the commands “ls -l” and “chown”, and following the steps described above, you can easily change the owner of a folder in Linux.
Be the first to comment