1

I am able to execute the command: cd /var/www/test; tail -f log/*.log; in remote with ssh connection as:

ssh -t user@xx.yy.zz.aa "cd /var/www/test; tail -f log/*.log; exec $SHELL -l"

which works great.
But as soon as I press Control + C just to stop the command to do something else, it closes the connection saying

Connection to xx.yy.zz.aa closed.

How to prevent this and stay connected even after pressing Control + C?

  • I second Hauke's answer: the Ctrl+C should be passed to the remote side and the remote shell should not terminate on Ctrl+C. Tell us how to reproduce what you did: how you open the terminal that you run ssh from, what terminal it is, what $SHELL is, try to reproduce it without any configuration files and if you can't post the relevant files, etc. – Gilles Sep 6 '17 at 22:35
  • I am using Mac OS's ITerm2 terminal and zsh as shell – MagePsycho Sep 7 '17 at 5:29
  • I just tried running ssh -t localhost 'exec /bin/zsh -l' using iterm2 on a mac, and Ctrl-C works as expected--it interrupts commands running on the remote system, but not the remote shell itself or the ssh connection. – Kenster Sep 7 '17 at 16:34
  • @Kenster Have you tried in remote? – MagePsycho Sep 8 '17 at 8:17
0

That should not happen. ssh should turn off signal generation in the terminal.

You can try to trap SIGINT in the shell which calls ssh

trap '' SIGINT

but the processes on the other side will not receive the signal then either.

You may also try to send a literal ^C to ssh by pressing

^V^C

The ^V is usually the "quoting" character for the terminal. I.e. instead of interpreting ^C as to generate a signal it is just passed on literally.

  • I am not sure what you mean. Can you write the full command how it should be executed? – MagePsycho Sep 8 '17 at 8:18
  • @MagePsycho Those are the full commands. – Hauke Laging Sep 8 '17 at 8:32
  • trap '' SIGINT && ssh -t user@xx.yy.zz.aa "cd /var/www/test; tail -f log/*.log; exec $SHELL -l" ? – MagePsycho Sep 8 '17 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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