Blog | G5 Cyber Security

Add Email Forwarder via Command Line

TL;DR

Yes, you can add an email address to a cPanel account’s forwarders list without using the cPanel interface. This is done through SSH access and command-line tools.

How to Add an Email Forwarder Without cPanel Access

  1. Access Your Server via SSH: You’ll need Secure Shell (SSH) access to your web hosting server. Use a terminal application (like Terminal on macOS/Linux or PuTTY on Windows). Connect using your username and password, or an SSH key.
    ssh user@yourdomain.com
  2. Identify the Account: Determine the cPanel account you want to modify. If you have multiple domains hosted on the server, you may need to specify which account’s email forwarders you are changing.
  3. Use the /usr/local/cpanel/bin/forwarder script: This is the primary tool for managing email forwarders from the command line.

    The basic syntax is:

    /usr/local/cpanel/bin/forwarder --add user@yourdomain.com destination_email@example.com
    • Replace user with the username of the cPanel account.
    • Replace yourdomain.com with the domain name associated with the account.
    • Replace destination_email@example.com with the email address you want to forward messages to.
  4. Example: To add a forwarder for info@yourdomain.com forwarding to myotheremail@gmail.com, use:
    /usr/local/cpanel/bin/forwarder --add info@yourdomain.com myotheremail@gmail.com
  5. Verify the Forwarder: You can verify that the forwarder has been added using the command line:
    /usr/local/cpanel/bin/forwarder --list user@yourdomain.com

    This will output a list of all existing forwarders for the specified account.

  6. Error Handling: If you encounter errors, check:
    • That the username and domain name are correct.
    • That the destination email address is valid.
    • Your server’s permissions; you may need root access for certain operations (though this script generally works within user accounts).

Important Note: Always be careful when using command-line tools, as incorrect commands can have unintended consequences. Back up your data regularly.

Exit mobile version