Linux forwarding-ports mail traffic over ssh

November 15, 2010 by: upa_kid

It is use to keep network traffic secure. Common examples are pop3, smtp, http protocols. If you are using DSL or wireless network then hackers (read as crackers) can read the your sensitive information such as email user-name, password, email contains, ftp login information etc. Recently friend of mine told me that his smtp login information is used to send spam email to thousands of users. Solution is simple use ssh to forward arbitrary TCP ports to the other end of your connection, so that you can protect the emails, web, ftp traffic etc.

Consider following scenario:
Normally from your workstation you directly pull or send email via ISP server. But with the help of remote ssh server you can secure the traffic. These days most of ISP don’t provide the ssh access to pop3/smtp server. Then solution is use the your universities shell account or free service providers such as or server provided by your work place. If you don’t have remote ssh server then stop reading this post.
click to view image

Your ISP pop3 server name:
Your remote ssh server name: or
Your remote ssh server login name: vivek
Considering above information your ssh command will be as follows:
A) Login as root user type the command (when prompted for password, type vivek’s password on :
# ssh -f -N

-f: Requests ssh to go to background just before command execution.
-N: Indicates we are forwarding port i.e do not open shell prompt.
-L : This is use to define a tunnel of port 110 on local system to port 110 on It uses following syntax:
port:host:hostport which means given port on the local (client) host is to be forwarded to the given host and port on the remote side. Remote ssh user (vivek) and server name (
Here is another example where I’m using yahoo pop3 and smpt server to send and receive email via’s shell account:
# ssh -f -N
# ssh -f -N -L

Please note this is quite useful when you are on wireless network (laptop) or when you don’t truest your local network. If your mail server also provides the ssh access then command would be:
# ssh -f -N -L

Naturally next step is to reconfigure your mail client such as Thunderbird or any other mail client, make sure you use pop3 server as localhost and rest of the configuration remain as it is, here is sample configuration:

POP3 Server: localhost
Port: 110
Username: my-pop3-username ( username)

Please note that secure SSH tunnel only works while you maintain a connection to remote UNIX/Linux SSH server. If you disconnect from remote ssh server or quit the SSH session, your tunnel also goes down.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
Have you found this script useful? Please support author by PayPal donation.

Leave a Reply