0

Note: I read and tried the solutions here: How do I remove an SSH forwarded port They did not work for me.

Note: I do not really understand how this works, so extra explanation so that I can learn would be appreciated

I have a docker container running on a remote system where I port map as follows:

docker run --it --rm ... -p abcd:wxyz container:tag

where abcd and wxyz are ports (e.g. 2222:8000)

Then on my local system I would like to listen to the ports at the remote system. I can do this via:

ssh -N -f -L localhost:abcd:localhost:abcd user@host

and like magic things work and I am happy. However, this does not automatically clean up when I am done with it. So I would like to know how to remove the specific listening.

I have tried:

$ ps aux | grep "ssh -N -f -L"
# user 23131   0.0  0.0  4268296    676 s005  S+   11:35AM   0:00.00 grep --color=auto ssh -N -f -L
$ kill 23131
-bash: kill: (23131) - No such process

so that didn't work.

Then I tried many variations of the following and always get:

ssh -O cancel -N -f -L localhost:abcd:localhost:abcd user@host
# No ControlPath specified for "-O" command

So what is the proper way to do this?

SumNeuron
  • 121
  • 4
  • 2
    Does this answer your question? [Finding the process that is using a certain port in Linux](https://superuser.com/questions/42843/finding-the-process-that-is-using-a-certain-port-in-linux) – Kamil Maciorowski Jan 03 '20 at 21:07

1 Answers1

0

First of all I would start looking for your ssh session by just using:

ps aux | grep ssh

as your search didn't find anything (did you put more then one space somewhere?).

For the other command (using -O ssh option) you need control socket. Have a look at -M and -S ssh options and ControlPath and ControlMaster in ssh_config man page.

Tomek
  • 1,133
  • 7
  • 9
  • I dont follow. My search shows the command I ran? As for the later, as stated in the post, I dont really get how this stuff works, so a bit more guidance would be appreciated – SumNeuron Jan 03 '20 at 19:34
  • Yes, it shows the command you've run: `grep --color=auto ssh -N -f -L` and grep is probably aliased to `grep --color`. This may have caused -N -f -L to be accidentally passed to `grep` as options, not part of the search string. I would say it is likely that `ssh` is already gone. Just try the command I proposed and check if it reveals any `ssh` commands still running. – Tomek Jan 03 '20 at 20:16