View previous topic :: View next topic |
Author |
Message |
eivinn Apprentice
Joined: 10 Jul 2002 Posts: 219 Location: Norway
|
Posted: Sun Dec 15, 2002 10:36 am Post subject: Loop-back ssh session? |
|
|
Hi,
I'm going away for christmas and is behind a strict NAT network. I'm not able to open any ports, but would really like to be able to still use my computer.
I don't know if it's possible, but I would like a c++ program or bash script to automaticly log onto a predefined server with ssh regulary when a connection is lost. Preferably I would then be able to do a loop-back connection and get X-forwarding from the connecting box instead of the usual opposite.
Is this possible |
|
Back to top |
|
|
Larde Guru
Joined: 07 Jun 2002 Posts: 313 Location: Duesseldorf, Germany
|
Posted: Sun Dec 15, 2002 10:43 am Post subject: |
|
|
I think you don't even need to program anything. Just use public key authentication so that you don't need to type in a password, fire something like ssh -l username -R 2704:localhost:22 some.server.outside from crontab, or /etc/inittab with respawn. Then on some.server.outside connect to 2704 (hey, that's my birthday! ) and you will be forwarded to your own server on ssh port 22.
Yours,
Larde. _________________ Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
|
|
Back to top |
|
|
eivinn Apprentice
Joined: 10 Jul 2002 Posts: 219 Location: Norway
|
Posted: Sun Dec 15, 2002 10:50 am Post subject: |
|
|
Great!! Just too bad I can't try this already...
cron.hourly will do won't it? and what happens if I already am connected? |
|
Back to top |
|
|
Larde Guru
Joined: 07 Jun 2002 Posts: 313 Location: Duesseldorf, Germany
|
Posted: Sun Dec 15, 2002 10:54 am Post subject: |
|
|
Well, we used to use this spawning from /etc/inittab, with respawn after the connection breaks for some reason. And the connection might be drop after a timeout, I don't know what firewalls are involved.
If you use it from crontab, you'd probably call a script that checks with some sort of ps and grep invocations if there is still an ssh connection running. Perhaps copy the ssh binary to tunnel-ssh and use that to connect outside, then grep for tunnel-ssh in your script.
Ah, there might be a problem with the port you use, you might need a timeout of 5 mins or so if the server on the other side keeps the port open after the connection breaks. I remember we sometimes had problems with that.
Hth,
Larde. _________________ Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
|
|
Back to top |
|
|
eivinn Apprentice
Joined: 10 Jul 2002 Posts: 219 Location: Norway
|
Posted: Sun Dec 15, 2002 11:11 am Post subject: |
|
|
This seams to be a good way to do it... Thanks again!
Eivinn |
|
Back to top |
|
|
Larde Guru
Joined: 07 Jun 2002 Posts: 313 Location: Duesseldorf, Germany
|
Posted: Sun Dec 15, 2002 11:45 am Post subject: |
|
|
I just tried the inittab approach again. Putting Code: | tnnl:2345:respawn:ssh -N -l kn -i /home/knielsen/.ssh/id_rsa -R 12704:localhost:22 moonage.net |
in /etc/inittab seems to work for me, where knielsen is my user where I start it, and kn is my user on moonage.net. Now I can connect directly to my work station in my company if I connect to 12704 on moonage.net. If you do experience reconnect problems after breakdown, try using something like at now + 5 minutes <ssh command>, but I didn't test that.
Hth,
Larde. _________________ Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
|
|
Back to top |
|
|
eivinn Apprentice
Joined: 10 Jul 2002 Posts: 219 Location: Norway
|
Posted: Sun Dec 15, 2002 1:00 pm Post subject: |
|
|
I tried testing at now +5 minutes in my shell prompt, but I haven't got any command that's called at or now...
I'm quite new to Linux so please fill me in.
Your inittab seems to work fine as it is, but I haven't tested it extensively. |
|
Back to top |
|
|
Larde Guru
Joined: 07 Jun 2002 Posts: 313 Location: Duesseldorf, Germany
|
Posted: Sun Dec 15, 2002 1:34 pm Post subject: |
|
|
Well, if it works without at, don't bother. I also noticed that the at command isn't installed by default. It's similar to cron, but for commands that shall be run once, not periodically. So with at installed (emerge at) and the atd running, at now + 5 minutes <something> would run <something> 5 minutes from now. Hmm, now that I think of it, sleep 600 would be easier and would have the same effect. Well, it's probably not even neccessary, to have a delay.
Larde. _________________ Someday this will be my home... http://moonage.net/
I'll make you a deal
I'll say I came from Earth and my tongue is taped
|
|
Back to top |
|
|
pjp Administrator
Joined: 16 Apr 2002 Posts: 20586
|
Posted: Sun Dec 15, 2002 7:32 pm Post subject: |
|
|
Moved from OTG. _________________ Quis separabit? Quo animo? |
|
Back to top |
|
|
|