How to remove / terminate a cPanel account using the Linux terminal

On this post we will explore how to delete or terminate a cPanel account using the Linux terminal / CLI (command line interface).

Remove / terminate a cPanel account from command line

In older versions of cPanel software, to terminate a cPanel account you needed tu run this script:

/scripts/killacct

or

/usr/local/cpanel/scripts/killacct

The right sintax to delete a cpanel account on the old cPanel versions was:

/scripts/killacct username

However, that doesn’t work on updated cPanel releases.

How to terminate a cPanel account on latest cPanel versions

On latest cPanel versions the old scripts don’t work anymore, and you need to use the new ‘removeacct‘ script:

/scripts/removeacct

or

/usr/local/cpanel/scripts/removeacct

The right syntax to remove a cpanel account using command line should be:

/scripts/removeacct username

Output example:

[[email protected]:~] /scripts/removeacct cptips --force
Running pre removal script (/usr/local/cpanel/scripts/prekillacct)......Done
Collecting Domain Name and IP......Done
Locking account and setting shell to nologin......Done
Removing Sessions.........Done
Killing all processes owned by user......Done
Removing Suspended Info.........Done
Removing Web Logs......Done
Removing Bandwidth Files......Done
Removing any unneeded pending interface locks......Done
Removing Email Sending Limits Cache......Done
Removing DKIM keys......Done
Removing Crontab......Done
Removing IPv6......Done
Removing external authentication links …......Done
Running AutoSSL account deletion logic …......Done
Removing domain TLS resources …......Done
Removing HTTP Virtual Hosts......Done
Removing ftp Virtual Hosts......Done
Removing user's web content directory symlinks......Done
Removing MySQL databases and users......Done
Revoking MySQL Privs.......Done
Removing PostgreSQL databases and users......Done
Removing Two-Factor Authentication entries..........Done
Removing User & Group..........Done
Removing DNS Entries......Done
Removing Email Setup......Done
Removing mailman lists......Done
Updating Databases......Done
Removing bandwidth limits......Done
Removing Counter Data......Done
Adding IP back to the IP address pool......Done
Removing user's cPanel Databases & Updating......Done
Reloading Services......Done
Removing mail and service configs......Done
Sending Contacts......Done
Updating internal databases......Done
Running post removal scripts (/usr/local/cpanel/scripts/legacypostkillacct, /usr/local/cpanel/scripts/postkillacct)......Done
Account Removal Complete!!!......Done
User: cptips
Domain: nixcp.com
Removed the following non-SSL virtual hosts: nixcp.com
Removed the following SSL virtual hosts:

Listing MySQL dbs for removal.
Fetching MySQL DB Owner information.

Successnixcp.com => deleted from server.
Removing /etc/valiases/nixcp.com
System has 23 free ips.

cptips account removed
[[email protected]:~]

Now you know how to terminate cpanel accounts from the linux terminal / command line with a single command. Note I passed –force to avoid confirmation (yes or no) while running the process.

How can I terminate multiple cPanel accounts from command line?

You can use a for loop, for example:

for cpuser in user1 user2 user3; do /scripts/removeacct $cpuser --force; done

How can I terminate all cpanel accounts from command line?

You can delete / terminate all cpanel accounts from the server by running a for loop against /var/cpanel/users directory, example:

cd /var/cpanel/users
for cpuser in *; do /scripts/removeacct $cpuser --force; done

About the Author: Martin Keler

Leave a Reply

Your email address will not be published. Required fields are marked *