Cloud Linux, Control Panel, CPanel / WHM

whmapi to create and delete cPanel account using SSH

If you want to create the cPanel account using SSH then follow below instructions.

whmapi1 --output=jsonpretty createacct username='elinux1234' domain='elinux.co.in'

Kindly replace the username with the usrename you want and the domain name with the actual domain name.

It will give output like:

[[email protected]  ~]# whmapi1 --output=jsonpretty \
>   createacct \
>   username='elinux1234' \
>   domain='elinux.co.in'


{
   "data" : {
      "nameserverentry" : null,
      "nameservera" : null,
      "nameserver3" : "ns3.younameserver.com",
      "nameserver2" : "ns2.younameserver.com",
      "nameserver4" : "",
      "nameserverentry2" : null,
      "nameserver" : "ns1.younameserver.com",
      "nameservera4" : null,
      "nameserverentry4" : null,
      "nameservera3" : null,
      "nameserverentry3" : null,
      "package" : "default",
      "ip" : "x.x.x.x",
      "nameservera2" : null
   },
   "metadata" : {
      "reason" : "Account Creation Ok",
      "version" : 1,
      "output" : {
         "raw" : "Checking input data...Dns Zone check is enabled.\nValidating Username......Done\nValidating IP......Done\nValidating Contact Email......Done\n...Done\nValidating system setup......Done\nChecking for database conflicts......Done\nWWWAcct 12.6.0 (c) 2022 cPanel, L.L.C....\n\n+===================================+\n| New Account Info                  |\n+===================================+\n| Domain: elinux.co.in\n| Ip: x.x.x.x (n)\n| HasCgi: n\n| UserName: elinux1234\n| PassWord: 65YDF8Q_d2nIKf\n| CpanelMod: paper_lantern\n| HomeRoot: /home\n| Quota: unlimited\n| NameServer1: ns1.younameserver.com\n| NameServer2: ns2.younameserver.com\n| NameServer3: ns3.younameserver.com\n| NameServer4: \n| Contact Email: \n| Package: default\n| Feature List: default\n| Account Enhancements: None\n| Language: en\n+===================================+\n...Done\nCustom Account Data Provided: no\nRunning pre creation script (/usr/local/cpanel/scripts/prewwwacct)...Ok\n...Done\nAdding User...Removing Shell Access (n)\nSuccess...Done\nAdding Entries to userdata......Done\nSetting up Mail & Local Domains...localdomains...valiases ...vdomainaliases ...vfilters ......Done\nConfiguring DNS...Zone elinux.co.in has been successfully added\n...Done\nVerifying MX Records and Setting up Databases...Reconfiguring Mail Routing:\nLOCAL MAIL EXCHANGER: This server will serve as a primary mail exchanger for elinux.co.in's mail.:\n This configuration has been manually selected.\n\n...Done\nSetting up Service Subdomains......Done\nUpdating Authentication Databases......Done\nSetting passwords......Done\nUpdating the userdata cache......Done\nSetting up Horde database in the background.......Done\nCreating bandwidth datastore......Done\nUpdating the dedicated IP address usage cache......Done\nGenerating and installing DKIM keys......Done\nEnabling Apache SpamAssassin™......Done\nSending Account Information......Done\nRunning post creation scripts (/usr/local/cpanel/scripts/legacypostwwwacct, /usr/local/cpanel/scripts/postwwwacct, /usr/local/cpanel/scripts/postwwwacctuser)......Done\nwwwacct creation finished\nAccount Creation Complete!!!...Account Creation Ok...Done\n"
      },
      "command" : "createacct",
      "result" : 1
   }
}
[[email protected]  ~]# 

You can use package name string to mention package pkgname=my_new_package or [email protected]

Now next is to delete the created account.

whmapi1 --output=jsonpretty removeacct username='elinux1234'

replace username with the actual username.

It will show output like below:

[[email protected] ~]#   whmapi1 --output=jsonpretty \
>   removeacct \
>   username='elinux1234'

{
   "metadata" : {
      "result" : 1,
      "reason" : "elinux1234 account removed",
      "command" : "removeacct",
      "output" : {
         "raw" : "Running pre removal script (/usr/local/cpanel/scripts/prekillacct)...no configuration found for VE 5401\n1 Ok\n...Done\nCollecting Domain Name and IP...User: elinux1234\nDomain: elinux.co.in\n...Done\nLocking account and setting shell to nologin......Done\nKilling all processes owned by user......Done\nRemoving Suspended Info.........Done\nRemoving Bandwidth Files......Done\nRemoving Email Sending Limits Cache......Done\nRemoving Crontab......Done\nRemoving public contact information …......Done\nRemoving external authentication links …......Done\nRunning AutoSSL account deletion logic …......Done\nRemoving installed TLS resources …......Done\nRemoving AutoSSL exclusions …......Done\nRemoving outgoing email suspensions and holds …......Done\nRemoving DKIM keys …......Done\nRemoving MX cache …......Done\nRemoving sessions for cPanel services …......Done\nRemoving any unneeded pending interface locks …......Done\nRemoving GNU Mailman mailing lists and archives …......Done\nRemoving web logs …......Done\nRemoving mail and service configurations …......Done\nRemoving any port authority assignments …......Done\nStopping any cPUser Service Manager based services …......Done\nRemoving child accounts …......Done\nRemoving linked-node account cache entry …......Done\nRemoving web hooks …......Done\nReclaiming any Account Enhancement usages for resellers …......Done\nRemoving HTTP virtual hosts...Removed the following non-SSL virtual hosts: elinux.co.in\nRemoved the following SSL virtual hosts: elinux.co.in\n...Done\nRemoving FTP virtual hosts......Done\n...Done\nRemoving user's web content directory symlinks......Done\nRemoving Two-Factor Authentication entries..........Done\nRemoving MySQL databases and users...\nListing MySQL dbs for removal.\nFetching MySQL DB Owner information.\n\n...Done\nRevoking MySQL Privs.......Done\nRemoving PostgreSQL databases and users......Done\nRemoving WHM API Token entries..........Done\nRemoving cPanel API Token entries..........Done\nRemoving User & Group.......Success...Done\n\nUpdating Databases......Done\nRemoving bandwidth limits......Done\nRemoving Counter Data......Done\nRemoving user's cPanel Databases & Updating...1...Done\nAdding IP back to the IP address pool...System has 3 free ips.\n...Done\nReloading Services......Done\nSending Contacts......Done\nUpdating internal databases......Done\nRemoving DNS Entries...Zones removed: 1\n...Done\nRunning post removal scripts (/usr/local/cpanel/scripts/legacypostkillacct, /usr/local/cpanel/scripts/postkillacct)......Done\nAccount Removal Complete!!!...\nelinux1234 account removed...Done\n"
      },
      "version" : 1
   }
}
[[email protected] ~]#