1

I frequently need to connect to a database instance on AWS, so I use an SSH tunnel. I can create one with the following command:

ssh -N -L 12345:some-database.rds.amazonaws.com:5432 [email protected]

This works great. However, when I want to disconnect, my only option seems to be CTRL + Z, which results in:

^Z[1]  + 12656 suspended

If I try to use port 12345 again, it says it's already in use. I have to kill the suspended process with:

lsof -t -i:12345 | xargs kill -9

This seems like a hassle. Is there a more convenient way to properly shut down an SSH tunnel when I'm done using it? Thanks!

4
  • 2
    In Linux I would expect Ctrl+c to terminate ssh; and it does work. I don't know macOS though. Do you run ssh in a way that makes it ignore SIGINT? And maybe some other signals? Is this the reason you use kill -9 instead of sole kill? Or do you reconfigure the tty, so Ctrl+c is not special? Commented Aug 30, 2023 at 18:24
  • @KamilMaciorowski: He's using CTRL+Z which apparently does the same as in Linux to suspend the process, but he's not using CTRL+C. The exit command might close the tunnel.
    – harrymc
    Commented Aug 30, 2023 at 18:32
  • 2
    @harrymc Well, my first comment was meant to be a polite equivalent of "why on Earth don't you use Ctrl+c for this?". Commented Aug 30, 2023 at 19:03
  • @KamilMaciorowski / @harrymc Hah, ok you two are completely correct I'm an idiot. The answer is because I had CTRL+C bound to a custom keyboard shortcut and it was blocking the normal behavior. Posted my answer, but honestly it's just because I'm stupid and should stop using Macs. Commented Aug 31, 2023 at 1:33

1 Answer 1

1

Thanks for the help! I figured this out, and it's mainly because I'm stupid.

Those who commented above as to why I'm not using CTRL+C instead of CTRL+Z are on to something. The answer is basically, "Well I tried and nothing happened".

I just figured ssh didn't support that, but I decided to dig in a bit more. Ok, so why does nothing happen?

The answer to that is because I'm using the Warp terminal, and had CTRL+C bound to the "Copy" command because I use Windows and Linux a lot, and prefer this to the MacOS Cmd+C. It seems that this was blocking the default ^C handler.

I've decided to just change back to the default keyboard shortcuts in Warp and the problem went away.

2
  • 1
    I guess if you instead defined a keyboard shortcut that sends ^C, i.e. ASCII ETX, a byte 0x03, then you could use the new shortcut to interrupt commands. The magic that "translates" ^C to SIGINT is implemented deeper; on the level of Warp you just need to pass the byte. Commented Aug 31, 2023 at 4:13
  • Yea, the feature that Warp needs is to ignore the keyboard binding if there's no actual text selected. I've logged a bug on this issue. Commented Aug 31, 2023 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .