0

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?

thatlamguy
  • 111
  • 2
  • This question appears to be off-topic because it is about [`working with a service provider's management interface, such as cPanel`](http://serverfault.com/help/on-topic). – HopelessN00b Jan 13 '15 at 22:22
  • There is a way to do that http://forums.cpanel.net/threads/how-to-add-user-to-whm.460891/#post-1860101 – JackTheKnife Mar 25 '15 at 14:52

1 Answers1

0

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
Garrett
  • 1,272
  • 10
  • 16
  • 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 06 '12 at 03: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 06 '12 at 04: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." http://forums.cpanel.net/f145/inserting-encrypted-password-into-password-generator-252461.html 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 06 '12 at 06: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 06 '12 at 15:01
  • There is now a way to do that: http://forums.cpanel.net/threads/how-to-add-user-to-whm.460891/#post-1860101 – JackTheKnife Mar 25 '15 at 14:52