The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

After transfer to new server /public_html have wrong user (root)

Discussion in 'General Discussion' started by tomfra, Sep 29, 2007.

  1. tomfra

    tomfra Well-Known Member

    Joined:
    Sep 30, 2002
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    Recently I transferred some accounts to a new server through WHM. The transfer went OK but some accounts have now the /public_html directory owned by root instead of their own account username. And since by default the permissions for public_html dirs are 750 (readable by user only), it is impossible to read/access anything in the public_html dir as a web visitor.

    I remember I may have had a similar problem several years ago but I am not sure. It didn't happen for all of the moved accounts for some reason.

    Is there a different solution than to fix the accounts one by one by hand?

    Tomas
     
  2. MaraBlue

    MaraBlue Well-Known Member

    Joined:
    May 3, 2005
    Messages:
    335
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Carmichael, CA
    cPanel Access Level:
    Root Administrator
    Yes.

    Login as root through SSH, and chown the account so it's owned by the user and not root.

    Code:
    cd /home
    chown -R user:user user_directory
    
    If I remember correctly, this may not cover the "." files (.lastlogin, .contactemail), and some directories need to be in other groups, such as public_html dhould be "user:nobody", mail should be "user:mail".

    My solution may not be the most eloquent, but until someone comes along with a better one, I'd compare another working user directory, chown the problem one with "chown -R" then go back through and adjust the child directories as needed to their correct groups.
     
    #2 MaraBlue, Sep 29, 2007
    Last edited: Sep 29, 2007
  3. tomfra

    tomfra Well-Known Member

    Joined:
    Sep 30, 2002
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    I know I can do it this way but I transferred 156 accounts and because I don't know how many accounts and which ones are affected by this problem, I would have to do it for all 156 of them. Not something I'd enjoy.

    Although I can code some PHP I don't know how to write shell scripts so I hoped there could be an existing script for this purpose already if it was indeed caused by a bug in the cPanel transfer system.

    I guess I'll simply copy all the account names and write a very simple shell script for it anyway.

    Tomas
     
  4. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    You can use this script which works nicely for more accurate quotas as well.

    #!/bin/bash
    cd /var/cpanel/users
    for user in *
    do
    chown -R $user.$user /home/$user/public_html/*
    done
     
  5. MaraBlue

    MaraBlue Well-Known Member

    Joined:
    May 3, 2005
    Messages:
    335
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Carmichael, CA
    cPanel Access Level:
    Root Administrator
    Ahh, sorry. I thought it was just one account affected. Moving to a new server is a PITA, innt? Jayh38 has posted a script for you, looks better than my way :) Good luck!
     
  6. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    The above script is very nice for keeping quotas near accurate. Not to go off track of the original subject, but its a good script to run daily. There is a cPanel script that will do nearly the same but it seems to make sites unavailable while its running which is not acceptable. Also the documentation states deleting of files. I think the document is just outdated for that script but anyway, this is the cpanel equivalent.

    /scripts/chownpublichtmls

    Good luck, hopefully this will help with some of your tasks ahead.
     
  7. MaraBlue

    MaraBlue Well-Known Member

    Joined:
    May 3, 2005
    Messages:
    335
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Carmichael, CA
    cPanel Access Level:
    Root Administrator
    "Quotas near accurate"? On a cPanel server? That's just an urban legend!

    :D
     
  8. tomfra

    tomfra Well-Known Member

    Joined:
    Sep 30, 2002
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    Thanks jayh38, your solution worked!

    Tomas
     
  9. tomfra

    tomfra Well-Known Member

    Joined:
    Sep 30, 2002
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    Actually, I had to chown the public_html dirs to user:nobody, not user:user. Apache apparently runs as user "nobody" on my machine. The files below public_html can be owned by the same group as the user though.

    Do I have a problem with my Apache setup? I think it normally does run as "nobody", right?

    Tomas
     
  10. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    Actually, thats part of getting quotas a bit more accurate. You should leave it as the user name and not as nobody because any files uploaded as nobody will not tally up in the quota for that user.

    I would run it again and set ownership as user.user as the script intended. You may see some accounts go over quota, LOL.

    I run this in cron.daily
     
  11. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    LOL, I hear ya. But atleast tally up the nobody megs against the account holder instead of a free ride.
     
  12. tomfra

    tomfra Well-Known Member

    Joined:
    Sep 30, 2002
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    The files themselves can be owned by the same group as user and all works OK. But the public_html directory itself has to be set to user:nobody, otherwise I get "permission denied" when trying to access any file in it through web browser. It's how it's set on my server.

    Tomas
     
  13. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    Right , public_html itsself would be nobody.user. I thought you meant individual files below that.

    Glad you are fixed up.
     
  14. verdon

    verdon Well-Known Member

    Joined:
    Nov 1, 2003
    Messages:
    836
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Northern Ontario, Canada
    cPanel Access Level:
    Root Administrator
    jayh38... I like your little script and use something similar myself on a couple of users who run very active photo gallery scripts. My concern is though, that once you change the ownership from nobody to user, yes the quotas get more accurate, but the user's CMS (or whatever script) can no longer do things with those files like move or delete them.
     
  15. cPanelNick

    cPanelNick Administrator
    Staff Member

    Joined:
    Mar 9, 2015
    Messages:
    3,426
    Likes Received:
    2
    Trophy Points:
    38
    cPanel Access Level:
    DataCenter Provider
    /scripts/chownpublichtmls
     
  16. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    Hmm.. I never actually ran into that problem. What do you do for them, just let them use all the "nobody" space they want?
     
  17. verdon

    verdon Well-Known Member

    Joined:
    Nov 1, 2003
    Messages:
    836
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Northern Ontario, Canada
    cPanel Access Level:
    Root Administrator
    I usually chown user:nobody and then chmod g+w That way, quota is more accurate and webserver can still write to the files/dirs
     
  18. jayh38

    jayh38 Well-Known Member

    Joined:
    Mar 3, 2006
    Messages:
    1,215
    Likes Received:
    0
    Trophy Points:
    36
    Thanks, I will keep that in mind.
     
Loading...

Share This Page