Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

ssh ssh 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.

share|improve this question

migrated from Nov 30 '11 at 14:08

This question came from our site for professional and enthusiast programmers.

Couldn't you use tmux or screen on the remote servers? That's what I've always done. – Rob Nov 30 '11 at 14:10
See this Q&A : To get it working in command line or in the shell, the ssh agent shall be forwarded too, eg using the ssh option "A" (see ssh man page), like : ssh -A user_foo@serverB "my_cmd" – hornetbzz Nov 30 '11 at 16:25

1 Answer 1

up vote 1 down vote accepted

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

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

  User piskvor
  ProxyCommand ssh -q nc -q0 22

What happens here:

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

This is completely transparent to your ssh client, so you can work with 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.

share|improve this answer
Thanks. After some more configuration this gives me a nice shortcut to ssh to server2: "ssh"... However, if I use "ssh tail -f file.log" I end up having the same problem. Ctrl+c kill the ssh connection, and leaves the tail process running. I want to run this command in a script, which opens multiple windows etc... so, I can not just ssh to server2 and manually type in the tail command. – Steve Hummingbird Nov 30 '11 at 14:46
Accepting your answer, as I never found myself wanting to script tail commands on remote servers, as connecting got much easier using your suggested configuration... I guess there is no more need to find an answer for my initial question – Steve Hummingbird Mar 12 '12 at 19:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.