Re: scripted ssh login



On 2007-07-28, Florian Schoenbeck <schoenbeck@xxxxxxxxxx> wrote:
I need to fetch some data from a Database which can be reached via
a ssh-tunneled TCP-port. Manually, everything works fine. First,
the ssh-connection is established and after that, the data is fetched.

Now I need to run this as a cron job, so I need to establish the
ssh-connection by script. That should work without problems because
the login is without password. But how can I shut down the connection
after the data is transfered?

What I used to do was run something like "sleep 5" with ssh -f and the
tunnel. If the sleep exits before the tunnel closes, the remote sshd
will wait for the tunnel to close before closing the ssh connection, so
the sleep just needs to be long enough to establish the tunneled
connection. This should work for most software and versions.

Another alternative, if you're using a recent OpenSSH, is to use the
ControlMaster option when establishing the connection, then use "ssh -O
exit" option to shut the master down when your script is done.

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
.



Relevant Pages

  • Re: What is The SSH?
    ... Building and Using SSH Tunnels ... What is an SSH tunnel? ... how to use it to make a connection to a server. ... You will need a working SSH client and server installation to build and test ...
    (microsoft.public.windows.server.networking)
  • SSH TCP forwarding: works with v1, not with v2 ssh
    ... that they're setting up the tunnels with no problem, ... I can get to the work ssh daemon: ... debug1: Connections to remote port 65002 forwarded to local address palimpsest:22 ... something answers (if I get "connection refused" there's no listener); ...
    (FreeBSD-Security)
  • Re: SSH TCP forwarding: works with v1, not with v2 ssh
    ... >that they're setting up the tunnels with no problem, ... >I can get to the work ssh daemon: ... > debug1: Entering interactive session. ... > Connection closed by foreign host. ...
    (FreeBSD-Security)
  • Re: sftp over two connections
    ... from there I log onto LIN and I can work on the console. ... > X tunneling works as well, and I tunnel additional ports to control ... > connection be tunneled through SSH so that I could mount LIN's ...
    (comp.security.ssh)
  • Re: PPP VPN solution over ssh tunnel?
    ... I run an ssh tunnel home from work all day long. ... I could run a traditional VPN connection ... but it worked for some things socks proxy did not. ...
    (comp.os.linux.networking)