Warning: remote port forwarding failed for listen port 'xxxx'

9,429

The correct command to see who is using port 2022 is

  sudo ss -ntp

First, you should not use nestat, which is by now obsolete (if you are on Linux, as I believe you are, but if you are on Unix just forget this); second, you should run the command as sudo, otherwise you will not have the authority to display the processes using the port; third, you should definitely not use the flag u, because this means looking at UDP ports, while you are getting an error on ssh, which is most definitely using TCP, not UDP.

Share:
9,429

Related videos on Youtube

eric f
Author by

eric f

LinkedIn

Updated on September 18, 2022

Comments

  • eric f
    eric f over 1 year

    How do I find the process that is listening on port 'xxxx' and kill it?

    I have RemoteForward 2022 remote.host:22 in my .ssh/config file.

    Whenever I ssh into a remote server: ssh staging-environment I am getting this error: Warning: remote port forwarding failed for listen port 2022

    I need this port open for port forwarding.

    How do I find the process that is listening on port 2022 and kill it?

    UPDATE:

    Output of netstat -tulpn

    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
    tcp        0      0 0.0.0.0:81                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:83                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:84                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:85                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:86                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:2022              0.0.0.0:*                   LISTEN      -                   
    tcp        0      0 127.0.0.1:2023              0.0.0.0:*                   LISTEN      -
    
  • eric f
    eric f over 10 years
    I've added the output of netstat. There is no process listed for port 2022. Why would this be?
  • eric f
    eric f over 10 years
    I think the problem may have to do with multiple old ssh connections. When I ps -ef | grep ssh I can see multiple sessions created by my user (and if they are listed, that means they are still active right?) and what looks to be some git processes running ...
  • Matthew Williams
    Matthew Williams over 10 years
    That could be the case. If you have old connections dotted about they would need to be pointed at something. If you want to start digging into your ssh connections this might help you. stackoverflow.com/questions/17199089/…
  • Matthew Williams
    Matthew Williams over 10 years
    Out of interest have you checked to see if anything is already listed for it under your router? Might have left yourself a note saying what it is.