How to reset / re-create user folders?

ozgurerdogan

Verified User
Joined
Apr 20, 2008
Messages
343
Hello,
Sometimes some users deletes puplic_html folder or some other needed files. Is there a script which would allows to create default folders for a domain?
 
Thanks for the respond. Actually I need to re-create for one user only. But help show for all user. How can I modify those codes for my need?
You think this works:
-
Code:
#!/bin/sh
 i = "abc"
 for d in `cat /usr/local/directadmin/data/users/${i}/domains.list`; do
 {
  mkdir -p /home/${i}/domains/${d}/public_html/cgi-bin
  mkdir -p /home/${i}/domains/${d}/private_html
  mkdir -p /home/${i}/domains/${d}/public_ftp
  mkdir -p /home/${i}/domains/${d}/stats
  mkdir -p /home/${i}/domains/${d}/logs
 };
 done;
 mkdir -p /home/${i}/backups 

 chown -R $i:$i /home/${i}
 chmod -R 755 /home/${i}

done;
exit 0;

Thanks in advance.
 
I don't know, what exact directories need to be recreated. Imap? SpamAssasin?

Change "abc" to your actual user name. And run the script
 
Perhaps, you'll need to fix rights on directories (ex. public_html). It depends on settings of your DA and related software.
 
I think this part of script:
Code:
chown -R $i:$i /home/${i}
chmod -R 755 /home/${i}
sets the correct permission?
 
Compare with the other users's homes. In my case /home/username has 711 and is owned by username:username.

Do you have "apache_public_html=0" in your /usr/local/directadmin/conf/directadmin.conf or "apache_public_html=1"?
 
Is it set to 0
But I am not trying to create usernamed folder. Only I want to recreate folder in that user's domain.
 
That's ok, "0" is good. Just chown /home/username or /home/username/domains to username:username.

Skip the line "chmod -R 755 /home/${i}". It will set 755 on all files and directories within the location (insecure).

If you re-create domain directory, add "chmod 711 /home/${i}/domain/" somewhere before the loop or after.

Add "chmod 711 /home/${i}/domain/${d}" within the loop.

I think that's all.
 
Yes that was an other point. I am not totally re-create domain folder. Only folder that DA creates as default. So I could edit the script and make it work as follows:
Code:
#!/bin/sh
user=usernamehere
domain=domainnamehere.com

mkdir -p /home/$user/domains/$domain/public_html/cgi-bin
mkdir -p /home/$user/domains/$domain/private_html
mkdir -p /home/$user/domains/$domain/public_ftp
mkdir -p /home/$user/domains/$domain/stats
mkdir -p /home/$user/domains/$domain/logs

mkdir -p /home/$user/backups 

chown -R $user:$user /home/$user
chmod -R 711 /home/$user

echo Done...

exit 0;

Can you please confirm that 711 is ok for /home/$user. Because when I look at other username I see 711. Also please note that I do not make any chmod for newly created folder.
 
711 for /home/$user is quite ok: apache, exim, dovecot need rights to access into user's home directory.

But if you want to be more secured (710 for /home/$user), you need to change much more, that is out of this topic.
 
You mean I should delete that line from script?

It's a bad idea to run it recursively. Plain text files (not executable scripts, like PERL) should have 644, not more.

If you want to do chmod recursively for directories only, run:

Code:
find /home/$user/*  -type d | xargs chmod 755

or

Code:
find /home/$user/*  -type d | xargs chmod 711

Be careful, with that command you can break user defined permissions on some directories.
 
Ok thank you. I think I do not need to set chmod for those default folder. So I deleted that line from script as I only need to re-create them.
 
Back
Top