ssh -L (오류 : 바인드 : 이미 사용중인 주소)


57

간단히, 나는 이것이 전에 나에게 일어난 일임을 알고 있습니다.AU에서 좋은 답변을 찾을 수 없습니다.

포트가 바인드 된 ssh 세션을 실행하고있었습니다 :

ssh -L 3000:<server_name>:22

연결이 끊어졌습니다.동일한 명령을 사용하여 다시 연결하려고하면 다음 오류가 발생합니다.

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 3000

포트를 다시 바인딩 할 수 있도록 내 컴퓨터에서 ssh를 어떻게 재설정합니까?로컬 머신 재설정이 작동합니다.

13

I suppose you have still something connected to local port 3000.

You can find it with

netstat -tulpn | grep 3000 

and then dispose of it. For example in my machine:

[:~] % netstat -tulpn | grep 5900
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      2547/vino-server
tcp6       0      0 :::5900                 :::*                    LISTEN      2547/vino-server

correctly identifies the process waiting and connected on port 5900 (vnc server).

Another useful command is

fuser 3000/tcp 

...all of them may need to be run with sudo if you do not own the process which is opening the port.


5

I was able to recreate and fix it by doing the following:

  • Open up something that will list your processes (ps -ae)
  • Kill the process called sh (kill <proc_number>)

Then reopen the ssh connection

Alternatively, I have had success with:

killall ssh

In the terminal on the local machine


77

Couldn't you just kill whatever is using that port?

 lsof -ti:5901 | xargs kill -9

lsof -ti:5901 to find whatever is using port 5901.

Pass the whole thing to kill -9 to kill whatever was using port 5901.

Replace with the port you want to open up again.


2

one more contender: ss

it can be used like this: ss -ltp | grep 3000 to find the program listening on port 3000