linuxpermissionschmodchownfile-ownership

changing the ownership of a folder in linux


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


Solution

  • 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.

    For example

    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.

    Edit:

    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.