Worth noting that you need a newline before the ~ for it to work.
Another useful tip to know is how to set your own escape key.
ssh -e ^ example.com
This will set the escape key to ^ instead of ~.
I had to use this recently to terminate an ssh connection that was initiated inside of a screen session on a machine I was sshed into from my laptop. Obviously, the generic ~. killed the first ssh session (on my machine), not the one in the screen. Connecting to the middle machine with ssh -e^ let me send ~. to the proper ssh session.
Another useful tip to know is how to set your own escape key.
This will set the escape key to ^ instead of ~.I had to use this recently to terminate an ssh connection that was initiated inside of a screen session on a machine I was sshed into from my laptop. Obviously, the generic ~. killed the first ssh session (on my machine), not the one in the screen. Connecting to the middle machine with ssh -e^ let me send ~. to the proper ssh session.