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

tomfra

Well-Known Member
Sep 30, 2002
68
1
158
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
 

MaraBlue

Well-Known Member
May 3, 2005
332
2
168
Carmichael, CA
cPanel Access Level
Root Administrator
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
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.
 
Last edited:

tomfra

Well-Known Member
Sep 30, 2002
68
1
158
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
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
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
 

MaraBlue

Well-Known Member
May 3, 2005
332
2
168
Carmichael, CA
cPanel Access Level
Root Administrator
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
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!
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
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.
 

MaraBlue

Well-Known Member
May 3, 2005
332
2
168
Carmichael, CA
cPanel Access Level
Root Administrator
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.
"Quotas near accurate"? On a cPanel server? That's just an urban legend!

:D
 

tomfra

Well-Known Member
Sep 30, 2002
68
1
158
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
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
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
 

tomfra

Well-Known Member
Sep 30, 2002
68
1
158
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.
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
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
Right , public_html itsself would be nobody.user. I thought you meant individual files below that.

Glad you are fixed up.
 

verdon

Well-Known Member
Nov 1, 2003
946
18
168
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.
 

jayh38

Well-Known Member
Mar 3, 2006
1,212
0
166
but the user's CMS (or whatever script) can no longer do things with those files like move or delete them.
Hmm.. I never actually ran into that problem. What do you do for them, just let them use all the "nobody" space they want?