How Does Openssh Implement Local Port Forward?

I started a sshd(using go-ssh) to listen ssh-client,

and run ssh -L 2345:127.0.0.1:5244 127.0.0.1 -p 2022 -N.

I didn't receive any message from client (include "direct-tcpip" ), but I can access web through 127.0.0.1:2345.

How does OpenSSH implement local port forward?

I hope than I can receive "direct-tcpip" from client.

sshConn, ch, globalRequestCh, err := ssh.NewServerConn(conn, config)
    if err != nil {
        log.Println("Handshake  err", err)
        return
    }

    log.Println("sshd serving", "ssh client", sshConn.RemoteAddr())

        
    go func() {
    // handle newChan
    for newChannel := range ch {
        log.Println("new channel", "type", newChannel.ChannelType())
        switch newChannel.ChannelType() {
        case "session":
                    
        case "direct-tcpip":
                    
        default:

            }
    }
    }()

    // handle globalRequest
    for globalRequest := range globalRequestCh {
    log.Println("global request", "type", globalRequest.Type)
    switch globalRequest.Type {
        case "tcpip-forward":

        case "cancel-tcpip-forward":

        default:
    
        }
    }
2
David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article