2

I'm connecting to a server via SSH for the SOCKS proxying like this:

ssh -N -D localhost:9050 myuser@example.org

The account just needs to proxy, so it has no terminal or anything.

The client is a standard Windows 10 PowerShell. Ssh worked out of the box there, nothing additional was installed to my knowledge.

I saw this other question, How do I exit an SSH connection?, but none of the answers work. This question is not a duplicate because the other question asks how to do it on Linux (see the tags) and this is about how to do it from Windows (PowerShell in particular).

I tried:

  • Typing exit + enter
  • Typing enter + ~
  • Typing enter + ~+&
  • Typing enter + ~ + ctrl+z
  • Typing the above but with a space after the tilde, because dead keys are on for my keyboard layout
  • Typing Ctrl+d
  • Typing Ctrl+c
  • Typing Ctrl+\
  • Closing Firefox, to terminate any remaining proxy connections. This worked previously when I did still have a shell, after using the 'exit' command it would hang (and I could not make it exit in any way) until Firefox was closed.

There is no shell now, so that an 'exit' command does not work is not weird, but somehow you have to be able to exit this shell right?

spikey_richie
  • 8,367
  • 2
  • 25
  • 42
Luc
  • 2,783
  • 2
  • 26
  • 37
  • Try "clean up your open sessions with `Get-PSSession | Remove-PSSession`" from [Getting Started using SSH with PowerShell](https://adamtheautomator.com/powershell-ssh/#Connecting_via_PowerShell_Remoting_and_SSH) – DavidPostill Mar 27 '21 at 17:50
  • 1
    Does this answer your question? [How do I exit an SSH connection?](https://superuser.com/questions/467398/how-do-i-exit-an-ssh-connection). I realize the author "tried" the exit command, but due to the new answer that suggests that command, this might as well be closed as a duplicate because that is **indeed** how you close an SSH connection. The platform nor the shell changes the fact the exit command works. – Ramhound Jul 08 '22 at 16:07
  • 1
    @Ramhound The platform nor shell changes some fact? Uh, it does. On Linux, enter+~+. works, on Windows it does not. How is this a duplicate from a question tagged *explicitly* for Linux where the situation is different? Then the linux tag should be removed on the question you marked as duplicate and you'd get answers that work for some but not all people with the same question. – Luc Jul 09 '22 at 12:17
  • 1
    tl;dr: `Ctrl`+`Break` | Apparently I don't have enough reputation to be allowed to answer the question, so I'm adding my answer as a comment. Hopefully it helps for your situation. I had a similar problem (wanted to cancel an ssh command if the server was not reachable, instead of waiting for a timeout or closing the window). I found [this question](https://stackoverflow.com/questions/42039231/ctrl-c-for-quitting-python-in-powershell-now-not-working) where the top answer recommended `Ctrl`+`Break`, and when I tried it myself, it worked! Again, hopefully this helps for you. – thejonwithnoh Jul 27 '22 at 11:11
  • Thanks @thejonwithnoh! I'd upvote your answer so you get more reputation and can post an answer but.... stackoverflow be stackoverflow. Will give this a try when I next use Windows :) – Luc Jul 27 '22 at 13:22

1 Answers1

0

To exit the Bash session, type "exit" without quotes and then the Enter key.

That should exit the SSH session and get you back to the PS C:\Windows\system32 prompt.

Just close the Powershell session by clicking on the X at the upper right corner of the window.

You said you tried this suggestion, but it just worked for me in Win10 Home with the latest updates (21H2) - I just edited a Hosts file on a network-attached Raspberry Pi4b. In your case, it sounds like you have no Bash session running, so this tip may not answer your question.

Qstik
  • 1
  • 1
  • "*In your case, it sounds like you have no Bash session running, so this tip may not answer your question.*" That is indeed the case. Thanks for the hint though! And yes, closing the window will work, I guess it was more out of curiosity that I would like to know what the Windows way of returning to your shell is (short of killing the process via external means). – Luc Jul 09 '22 at 12:15