The way to do that is by editing /etc/rc.local and putting the following in it:
su lindqvist -c 'autossh -N -f -M 29001 -R 19996:localhost:22 remoteuser@my.router.com' &
Make sure you put it before the line that says
exit 0
linqdvist is the user at on my work computer I want to be running the autossh, 19996 is the port I'll connect to on my home router to gain access to the ssh port on my work computer. Since I'm using WRT54G with Tomato the remoteuser is root, and I got my dns (remote hostname) as shown in this post: http://verahill.blogspot.com.au/2012/02/tomato-router-and-free-dns.html
It's that simple.
Thank you, I spent about 4 hours trying to make rc.local work on my raspberry pi with autossh. Logging in as a user instead of doing it on root with the "su user -c '' & did the trick for me.
ReplyDeleteThank you. Now it's working for me to.
ReplyDeleteWhy is su -c needed? adding it made things work for me but I dont understand why it has to be there
ReplyDeletesu lindqvist -c '' runs the command in '' as user lindqvist. Otherwise it'd be run as root.
ReplyDeleteThank you, that was helpful! Do I need to use su because of keys storage in user's home?
ReplyDeleteVery nice, I was just about to give up for a few hours and BAM you solved my problem. Thank You..
ReplyDeletesu user -c worked like a charm..