Run SSH SOCKS5 proxy on system startup

I want to setup a linux server (Ubuntu Server 14.04 in this case) to be used as a SOCKS5 proxy by software on another client.

Now this is pretty easy by running ssh -f -N -D 0.0.0.0:1080 localhost as explained by this guide. This works perfectly.

Now what the guide isn’t telling me is how do I automatically start the proxy on system startup? Just entering this command into rc.local isn’t working because I have to provide a passphrase. Generating a ssh key with ssh-keygen and putting it into /root/.ssh/ doesn’t work either.

Be noted that I don’t really understand how the whole ssh public key thing works, so my error might lie there. Anything special I have to do when my public key is supposed be used for the local client and not a remote client?

Asked By: timonsku

||

I fixed this by running ssh-keygen as root user (not sudo), not specifying any name for the key (e.g. use default name and location) and not providing any passphrase. Then I made sure the permissions for all files in /root/.ssh were set to 600 and the .ssh folder was set to 700.

Then just add the command from the question to run the proxy to your /etc/rc.local and you’re done.
As far as I understand this it is not a security risk to have no passphrase in this case as the public and private key only reside in the root folder of the local machine.

Answered By: timonsku
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.