Tuesday, October 12, 2010

Bind a non-root service to port 25 on Ubuntu with Authbind

Ports 1-1024 including 21 (ftp), 22 (ssh), 25 (smtp), 80 (http), 110 (pop3) can only be bound by services running as root.

Error messages indicating you have this problem are "Permission denied", "IOError when attempting to open socket ( constructor ), shutting down! java.net.BindException: Operation not permitted" or "java.net.SocketException: No such file or directory".

I recently developed my own smtp listener (converting e-mail to text/sms messages) and rather run the service as it's own user. Here's how (for port 25):

Install authbind (allows a program which does not or should not run as root to bind to low-numbered ports in a controlled way):
apt-get install authbind

Configure authbind (replace user with your user):
touch /etc/authbind/byport/25
chown user:user /etc/authbind/byport/25
chmod 755 /etc/authbind/byport/25

Start the service (simple test):
authbind nc -l -p 25 -e "/usr/bin/uptime"

Start the service (java):
authbind --deep /bin/bash -c "/usr/bin/java -Djava.net.preferIPv4Stack=true com.cent.texter.TexterServer"

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete