Manage cPanel mail forwarders via SSH
Posted on 23 Mar 2011 by Alan Burns
In an earlier article I described how mail forwarders work. They are a useful feature. So much so that some of us have long lists of forwarders for our domains.
Creation and editing of mail forwarders is normally handled via cPanel’s web interface. Those of us with long lists, though, now find it awkward due to a change made by cPanel developers to sub-divide long lists of items such as mail forwarders into multiple pages, as detailed in an earlier article.
If you have VPS (virtual private server) hosting plan, you might prefer to directly edit the file containing the forwarders. This can be achieved via an SSH connection. For security purposes, SSH may by default be disabled on your server, so you may need to request SSH access from your host.
Once logged in to your VPS as root, over SSH, change directory to etc/valiases/ :
In valiases you should see several files, one per domain. If you cannot find that directory, then ask your host, as configuration does vary somewhat, thought that is the most common path.
Use Midnight commander (‘mc’ command), ‘vi’ or ‘nano’ commands to edit those files. To create a forwarder, add lines in this format:
The last line is necessary to avoid delivery to non-existent mail accounts and addresses.
Root access is one of the many advantages of a VPS hosting plan. It provides more control, more features, and ways to directly access files that are often faster than using the cPanel GUI.