Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been using useradd to create user account on my CentOS server although cPanel has been installed on the server. For some reasons, I created them by command instead of using WHM.

Now, some of them want to use rich features of cPanel. What is the best solution here to add those account using cPanel without re-creating them through WHM?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

cPanel creates a whole wack of configuration files when you run through the Create Account Wizard so doing this process by hand would likely be more time-consuming and tedious than it would be to use the Wizard. That being said, if you only have home directory data to worry about for each user, you can easily just hack together a Bash script (like the one below :)) to move the home directory data out of the way (say /home/user.bak), kill the account (userdel -r user), create the account,and finally move the data back. Note that if the home directory for the user contains web content, under the cPanel directory schema, that content needs to be moved into ~/public_html.

Here's a very simple bash script, which takes a list of accounts from a text file and does what I mentioned above. Note the text file is formatted domain.com:user as cPanel won't create an account without a domain name. You'll have to setup this mapping manually when you create that file or come up with a way to script using awk/grep from your existing config. The script also creates a password for all of the accounts of 'temppass' -- make sure you change that! :)

#!/bin/bash

# Replace this with the file you use
FILE=/root/acctlist

for USER in `awk -F':' {'print $2'} $FILE`
do
  mv /home/$USER /home/$USER.bak
  userdel -r $USER
  DOMAIN=`grep $USER|awk -F':' {'print $1'}`
  /scripts/createacct $DOMAIN $USER temppass
  cp -a /home/$USER.bak/* /home/$USER/
  #Uncomment this if you're sure you want to remove the old dir
  # rm -rf /home/$USER.bak
done
share|improve this answer
    
Thanks gman, I actually thought about userdel then create them again in WHM, but the problem with old password removed as well is way too bad. Is it a good idea to notify them about temp password and force them to create a new one? –  thatlamguy Apr 6 '12 at 3:08
    
You could add a little extra to the script where you pull the password hash from /etc/passwd before deleting the account and then replacing it after the createacct script is run. Otherwise just use the Password Modification function in the WHM. –  Garrett Apr 6 '12 at 4:05
    
This is from cPanel forum: "Allowing this would permits users to bypass password strength checking as the password would be opaque to the interface." forums.cpanel.net/f145/… Yes, we are able to pull those password hash from shadow file, but cannot figure out how to insert the hashed password to WHM. –  thatlamguy Apr 6 '12 at 6:15
    
Password checking just enforces a particular password strength. If you're satisfied with your particular password setup, then that's not a problem. What would be a problem here is setting the MySQL and FTP passwords, as they use different hashing mechanisms, and there's no way to pass a hashed password to the WHM. –  Garrett Apr 6 '12 at 15:01
    
thanks for your help gman! –  thatlamguy Apr 8 '12 at 6:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.