Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I semi-accidentally ran this command on my MacOS terminal: ssh -L 9090:localhost:9090 174.143.140.9

My command prompt is now "localhost:~ pbreit$" which I am pretty sure is different from what it used to be (the "localhost" part).

How do I "undo" this? Or do I need to? My system seems to be working fine but I'm slightly nervous.

share|improve this question

3 Answers 3

As long as you see that prompt, you're simply connected to that remote system. What you're seeing is the prompt from the remote server, which has nothing to do with using port forwarding.

Type exit to disconnect, and then run the same command without -L 9090:localhost:9090 to see exactly the same prompt (hence: not related to the port forwarding). Likewise, after running exit or when opening another Terminal window you will see your local Mac's prompt just as you know it.

(To only do port forwarding without showing the prompt, you could use ssh -N -L ... instead, and then use Ctrl-C to disconnect.)

share|improve this answer

Exiting out of ssh will disconnect the tunnel. If there are no connections running over it then this can be done by exiting the remote shell.

share|improve this answer

As far as I can tell, there is no option at this time for cancelling a local port forward other than exiting your connection. It is possible to cancel a reverse port forward (from the remote machine back) using this syntax:

<RET><RET>~c  (press return twice and ~c to get the ssh command prompt)
-KR 9090:localhost:9090

This will cancel the port you've forwarded from the remote machine on port 9090 back to your local machine localhost:9090. I tried doing -KL 9090:localhost:9090 and it just said not supported. So I guess eventually it will be possible, but not right now. There is also an option called CancelAllForwardings, but unfortunately you can't use these options either inside the client console.

I tested this with OpenSSH 5.5p1 on Ubuntu, maybe a newer version does have the option, but I didn't see anything about it in the openssh changelog.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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