Linux : Change file/folder owner

On a Unix based system, all files and folders belong to a group and a owner. Or rather, an owner and a group has specific permissions to read, write and execute files. So you might need to change the owner of certain files and folders so that you’ll be able to open them, edit them and write to them again.

I’ll show you how to do this via SSH. You’ll need a login and password in order to access the shell.

ssh -lroot

Once logged in, change the directory to the one where the files/folders are located.

cd /var/www/vhosts/

Then you might want to recursively change the owner for all files and folders inside that directory to another user. Lets set the owner of the files and folders to “peter”

chown -R peter *

That is all there is to it. You have just changed the owner of all files and folders recursively inside the specified directory to “peter”. You can now open the files (for example via FTP), edit them and write back to them again. Good luck!


  1. avatar on March 29, 2011

    I would like to use some code which would enable me to change separately file permissions from folder permissions. The idea is to set FOLDER Permissions to 0755 and FILE Permissions to 0644. How to do that?

  2. Ivan on June 14, 2011

    Well done, that helped me out. Thanks

  3. James Velzy on July 16, 2011

    Where do you find the password for root? Eh?

  4. Les on November 20, 2011

    Thanks for this very useful post.
    I am always amazed (and a little scared) of how fast commands work in ssh –

    This one did the trick for me!

  5. Saleem Moahammad on November 22, 2011


    I am used this pattern, this pattern changed the group name but not change owner. I am write code here .

    $fileName = $root_directory.’user_privileges/user_privileges_’.$userid.’.php’;
    exec(“chown employhr $fileName”);
    exec(“chgrp -R employhr $fileName”);

    Please suggest me how I can do these fo change owner/group.


  6. Eduardo on December 2, 2011

    Hi thanks quick and nice…

    to add my little part if you want to change also the group not only the user.

    chgrp works pretty much the same way as chown does, except it changes the file’s user group instead of the owner, of course.

    $ chgrp usergroup somefile

    After issuing this command, the file somefile will be owned by a user group usergroup. Although the file’s group has changed to usergroup, the file’s owner will still be the same.

    The options of using chgrp are the same as using chown. So, for example, the -R and -v options will work with it just like they worked with chown:

    $ chgrp -Rv usergroup somedir
    changed group of ‘somedir/’ to usergroup
    changed group of ‘somedir/boringfile’ to usergroup
    changed group of ‘somedir/somefile’ to usergroup



  7. Pawan on December 13, 2011

    Thanks a lot.. It helped 🙂

  8. quimkaos on January 23, 2012

    is it possible to assign multiple users ownership to a folder? even if they don’t belong to the same user group? or multiple user group ownership to a folder?

  9. ligrex on January 30, 2012

    I did these steps (changing dir owner) for a web sites and all worked well. I did the same for another site on the same server but when i try to get into root directory a message appear “permission denied”. Can anybody help me, please?
    Thank you,


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: