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!
ssh
; and it does work. I don't know macOS though. Do you runssh
in a way that makes it ignore SIGINT? And maybe some other signals? Is this the reason you usekill -9
instead of solekill
? Or do you reconfigure the tty, so Ctrl+c is not special?exit
command might close the tunnel.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.