4
1
In short, every time my computer boots, I would like to start a ssh port-forwarding connection that will reconnect with the server if the connection drops. Computer is Debian Wheezy x64.
An initial and successful connection can be made as follows:
screen -dmS autossh autossh -M 29000 -N -v -p 22 -l user -i /path/to/.ssh/id_rsa -L port:my-computer:port my-server.com
How can this be made to run at startup? (preferably by user, not root). Here is currently how I have been starting programs at boot:
rc.local calls my startup script as follows:
su -c "/home/username/scripts/startup" username
Currently, /home/username/scripts/startup contains the following:
screen -dmS program1 python my-python-program
screen -dmS program2 python my-python-program2
screen -dmS autossh autossh -M 29000 -N -v -p 22 -l user -i /path/to/.ssh/id_rsa -L port:my-computer:port my-server.com
Once booted, all three programs appear to be running (by list screen -ls). There is no problem with program1 or program 2. However, autossh is not actually forwarding the port.
The difference between a successful connection run by me, and an unsucessful connection run at startup is that a successful connection has the line:
debug1: channel 4: free: direct-tcpip: listening port 8082 for 192.168.1.104 port 80, connect from ::1 port 59681,
nchannels 5
While the unsuccessful connection keeps trying like so:
debug1: Connection to port 8082 forwarding to 192.168.1.104 port 80 requested.
debug1: channel 4: new [direct-tcpip]
debug1: Connection to port 8082 forwarding to 192.168.1.104 port 80 requested.
debug1: channel 5: new [direct-tcpip]
debug1: Connection to port 8082 forwarding to 192.168.1.104 port 80 requested.
debug1: channel 6: new [direct-tcpip]
debug1: Connection to port 8082 forwarding to 192.168.1.104 port 80 requested.
debug1: channel 7: new [direct-tcpip]
debug1: Connection to port 8082 forwarding to 192.168.1.104 port 80 requested.
debug1: channel 8: new [direct-tcpip]
Any idea what is wrong? Why would a program work fine when I run it manually, but not inside my startup script?
Sorry - dont have the time for a full answer, but : http://www.harding.motd.ca/autossh/ should help you along the way.
– FreudianSlip – 2012-12-27T20:06:44.013