Skip to main content
All CollectionscPanel and WebHost Manager (WHM)SSH
Randomize an email password via SSH on a cPanel server (requires root)
Randomize an email password via SSH on a cPanel server (requires root)

Need to quickly change an email account's password, this one liner will randomize a password for any specified email account.

Justin Catello avatar
Written by Justin Catello
Updated over 7 years ago

Anytime we get alerts of outgoing spam via SMTP authentication which usually indicates a weak email password, we want to stop the spammer ASAP and the quickest solution is using SSH.

With the below one liner, change the email and hit enter.

email=justin@bigscoots.com ; uapi --user="$(/scripts/whoowns ${email#*@})"  Email passwd_pop email="${email%@*}" password="$(tr -dc 'A-Za-z0-9<=>?@[]\#)(' < /dev/urandom | head -c 64 | xargs)" domain="${email#*@}" ; /scripts/restartsrv_dovecot ; /scripts/restartsrv_exim ; exim -bp|grep "$email"| awk {'print $3'}| xargs exim -Mrm


Example of the output:

root@server [/]# email=justin@bigscoots.com ; uapi --user="$(/scripts/whoowns ${email#*@})"  Email passwd_pop email="${email%@*}" password="$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 64 | xargs)" domain="${email#*@}"
---
apiversion: 3
func: passwd_pop
module: Email
result:
  data: ~
  errors: ~
  messages: ~
  metadata: {}

  status: 1

The status 1 indicates that it has changed successfully.

10/04/2017: Updated the code to now restart both exim and dovecot to clear any sessions as we found that changing the password doesn't stop any current open sessions with the mail server which allows them to continue to send out email.

This will also remove ALL emails in the mail queue that are from the email you are changing the password for.

Did this answer your question?