- Change folder permissions and ownership
- 9 Answers 9
- How do I change the owner of a directory in Linux?
- chown command syntax
- Changing the owner of a directory
- Changing the ownership of all sub-directories
- Changing the owner of a file
- Changing the owners of multiple files
- Changing the owner of directory and file at once
- Changing the owner using wildcards
- Conclusion
- About the author
- Talha Saif Malik
- changing the owner of folder in linux [closed]
- 1 Answer 1
- Use chown to set the ownership of all a folder’s subfolders and files?
- 6 Answers 6
Change folder permissions and ownership
I would like the user to have full rights on this folder (as well as all sub-directories and files in it):
currently owned by root. I have found numerous posts (in this forum and elsewhere) on how to do this for files but I can’t find a way to do it for whole folders.
9 Answers 9
Use chown to change ownership and chmod to change rights.
As Paweł Karpiński said, use the -R option to apply the rights for all files inside of a directory too.
Note that both these commands just work for directories too. The -R option makes them also change the permissions for all files and directories inside of the directory.
sudo chown -R username:group directory
will change ownership (both user and group) of all files and directories inside of directory and directory itself.
sudo chown username:group directory
will only change the permission of the folder directory but will leave the files and folders inside the directory alone.
As enzotib mentioned, you need to use sudo to change the ownership from root to yourself.
Note that if you use chown : (Note the left-out group), it will use the default group for that user.
If you want to change only the group, you can use:
BEWARE of recursively taking ownership of ANY directory. Think before you leap. Don’t be chown copypastin’ from the internet, kids. Just because you want to install a node package and it won’t let you, don’t sudo chown -R just because the fist hit from googling the error message says to. Reckless sudo chown -R -ing can kill your OS.
It needs to be said that using the -R option only applies to files and folders that exist in the directory already. It does NOT apply to future creations. For example, if you create another folder or file as root within the folder you’ve already changed permissions on, you will have the same experiences you’re having now until you chmod\chown them again.
Make the current user own everything inside the folder (and the folder itself):
very helpful for newbies (like me) when don’t know what to type in ‘usergroup’ for sudo chown
If you prefer, this can be done with a GUI as well. You will need to open Nautilus as root to do so. Press Alt + F2 to access the «Run Applications» dialog and enter gksu nautilus
Next, browse to and right click on the folder you would like to modify. Then, select «Properties» from the context menu. You can now select the user or group that you would like to be the «Owner» of the folder as well as the permissions you would like to grant them. Finally, press «Apply Permissions to Enclosed Files» to apply the changes recursively.
Though it seems this does not always work for some operations in a deep folder tree. If it does not work use the appropriate terminal command.
How do I change the owner of a directory in Linux?
All files and directories that exist on your Linux system have an owner, a group, and permission access rights that are granted to the file owners, its group members, or others. The chown command permits a Linux user to change any directory or file’s ownership. In this post, we will demonstrate the usage of the chown command for changing ownership through practical examples. But firstly, you should understand why you would want to change the ownership of any directory or file?
Here is the list of few scenarios in which you want to do this:
- For example, you want an already created directory or file to be accessible to a particular user.
- When a user leaves an organization, all of his data comes under the responsibility of another employee. Therefore, you want to change the ownership of the new team member.
- Changing directory or file ownership is also necessary when you are writing a script that has to be used by only a specific person.
- Transferring files between different Linux systems also requires changes in files and directories ownership.
Now let’s check out the syntax of the chown command.
chown command syntax
Utilize the “User” for the username or replace it using the user ID, also known as UID. Add the group name in the “Group” part of the GID (group ID). At the end of the chown command, add files or directories for which you want to change the ownership.
Changing the owner of a directory
We have created a separate user named “utest” and a group “ugroup” for demonstrating the examples. To change the ownership of any directory, utilize the chown command with the username and path of the directory.
Now, write out the “ls” command and check if your directory ownership is updated or not.
Changing the ownership of all sub-directories
Utilize the “-R” option of the chown command for changing the owners of all the files or folders present in a directory.
List out the directory content to view the results.
Changing the owner of a file
First of all, list out the file content to know about its ownership.
After that, specify the name of the user who you want to be the new owner of this file. In our case, we have chosen “utest” to avail the ownership of “samplefile.txt.”
Again, verify the updated ownership changes.
You can also use the “User ID” or “UID” of any user for this purpose. For that, retrieve the user ID of the new user by utilizing the “id” command with the “-u” option.
Add the User ID instead of the username to make the ownership changes.
Changing the owners of multiple files
Specify the file names at the end of the chown command to change the ownership of multiple files at once.
Write out the below-given command to confirm the changes.
Changing the owner of directory and file at once
Follow the below-given method for changing the owners of the file and directory instantly.
This command will make “utest” the new owner of the “test directory” and the “samplefile.txt.”
Changing the owner using wildcards
Wildcards are used to select a specific file group according to the given pattern. The chown command will then change the owner of the files after retrieving them from the wildcard execution.
Conclusion
For data security concerns, you may want to specify the ownership of files and directories. In Linux, we use the chown command-line utility for changing the ownership of directories or files. You can also utilize this command for changing directories and multiple file ownership at once. In this post, all of these statements are justified by providing practical examples.
About the author
Talha Saif Malik
Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.
changing the owner of folder in linux [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
I have a folder in my subdomain which is created through WHM so the owner of that subdomain is not the owner of main domain. I want to change the owner of one of the folders of subdomain to domain owner. I tried this, but when I check with winscp it shows owner as 500.
chown users:user /home/xyz/somnething/photo/
I’ve tried to change from winscp also, but there is no option for winscp, so I’ve logged in as root using putty and ran the command from above, but it doesn’t help and I am unable to upload any file to subdomain from the main domain, as it returns error «permission denied».
$ ls -l /home/xyz/somnething/photo/ total 8 drwxr-xr-x 2 sujit sujit 4096 Feb 21 23:39 ./ drwxr-x--- 5 rohan nobody 4096 Feb 22 02:28 ../
I want to give the ownership of rohan to sujit to have rights to upload file from sujit domain to subdomain rohan Update: Now it is changing owner to 500
1 Answer 1
Use chown to change ownership and chmod to change rights.
use the -R option to apply the rights for all files inside of a directory too.
Note that both these commands just work for directories too. The -R option makes them also change the permissions for all files and directories inside of the directory.
sudo chown -R username:group directory
will change ownership (both user and group) of all files and directories inside of directory and directory itself.
sudo chown username:group directory
will only change the permission of the folder directory but will leave the files and folders inside the directory alone.
you need to use sudo to change the ownership from root to yourself.
Note that if you use chown user: file (Note the left-out group), it will use the default group for that user.
Also You can change the group ownership of a file or directory with the command:
chgrp group_name file/directory_name
You must be a member of the group to which you are changing ownership to.
You can find group of file as follows
# ls -l file -rw-r--r-- 1 root family 0 2012-05-22 20:03 file # chown sujit:friends file
User 500 is just a normal user. Typically user 500 was the first user on the system, recent changes (to /etc/login.defs) has altered the minimum user id to 1000 in many distributions, so typically 1000 is now the first (non root) user.
What you may be seeing is a system which has been upgraded from the old state to the new state and still has some processes knocking about on uid 500. You can likely change it by first checking if your distro should indeed now use 1000, and if so alter the login.defs file yourself, the renumber the user account in /etc/passwd and chown/chgrp all their files, usually in /home/, then reboot.
But in answer to your question, no, you should not really be worried about this in all likelihood. It’ll be showing as «500» instead of a username because o user in /etc/passwd has a uid set of 500, that’s all.
Also you can show your current numbers using id i’m willing to bet it comes back as 1000 for you.
Use chown to set the ownership of all a folder’s subfolders and files?
Will any of these answers work if the files inside a folder are owned by someone else and only have user read/write permission?
6 Answers 6
Usage: chown [OPTION]. [OWNER][:[GROUP]] FILE. or: chown [OPTION]. --reference=RFILE FILE. Change the owner and/or group of each FILE to OWNER and/or GROUP. [. ] -R, --recursive operate on files and directories recursively [. ]
So you need to run (probably with sudo ):
chown -R USERNAME:GROUPNAME /PATH/TO/FILE
Or, if the group shall be the specified user’s primary group (usually same name), you can also omit the GROUPNAME and just give the USERNAME: with a colon (no space before it!). It will be set implicitly:
chown -R USERNAME: /PATH/TO/FILE
To only change the user and leave the group as it is, just specify USERNAME and no group name and no colon:
chown -R USERNAME /PATH/TO/FILE
To only change the group and leave the owner user as it is, just specify :GROUPNAME with a leading colon:
chown -R :GROUPNAME /PATH/TO/FILE
My username is timo and I did this to take ownership to all my files and folders on home directory (transferred from another account):
~$ sudo chown -R timo /home/timo/*
This is how I normally do it, and I usually do this one folder at a time. Doesn’t take but a few moments to work through each folder.
This will also change ownership of symlinks instead of just the destination files that the symlinks point to.
man chown chown options user:group files/folders
Not sure why other answers did not cover one dot. : And . are interchangeable, so you can use one dot for instance
chown -R user.group files/folders
Either get to the terminal display mode as described elsewhere or do a ssh login from another computer. Usually the account is intact and it will be accessible via ssh.
You may also have an account on the same machine without the login loop problem. If you do, then login to that account (assuming it will let you sudo).
Once in, open a terminal and find the directory under which you can see the username directories. i.e. /home/username1 /home/username2
if any of the user directories is owned by root change it by running:
sudo chown -R username:username /home/username
This example is based on an architecture where the user directories are under /home/
Run ls -l again to confirm the directory is owned by the user.
This was tested on Ubuntu 20.04