2

I have been using the following command to connect to a server, which connects to another server and runs tail -f on it:

ssh server1.com ssh server2.com tail -f file.log

This so far works fine. However, when I want to quit the tail process by pressing ctrl+c, I do not quit the tail process, but the ssh process. This leaves the tail process on the remote server running, which obviosly is not a very good idea.

Does any one have an idea how I could fix this command line? I also would be interested if there is tool, running on os x, that would allow to comfortably switch between viewing different files on the remote server.

st-h
  • 123

1 Answers1

1

If you have netcat installed on server1.com (you probably do), you may want to use the ssh directive ProxyCommand to seamlessly hop across server1.com; thus, when you press Ctrl+C, it will only terminate the command on server2.com, not your SSH session.

Example of your ~/.ssh/config (create the file if it doesn't exist; append to end if it does):

Host server2.com
  User piskvor
  ProxyCommand ssh -q server1.com nc -q0 server2.com 22

What happens here:

  • ssh connects to server1.com
  • it remotely connects from there to server2.com (using nc)
  • which ferries the data through server1.com

This is completely transparent to your ssh client, so you can work with server2.com as if you were connected directly (e.g. SFTP, X forwarding, TCP forwarding, etc.)

For a more detailed explanation (as well as extending this to multiple hops), see this article, or this similar question on SU.