Skip to content

Commit

Permalink
Add localforward example
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM committed Nov 15, 2019
1 parent ef7b36b commit 0b90efa
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions _examples/ssh-localforward/localforward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"io"
"log"

"github.com/gliderlabs/ssh"
)

func main() {
log.Println("starting ssh server on port 2222...")

server := ssh.Server{
LocalPortForwardingCallback: ssh.LocalPortForwardingCallback(func(ctx ssh.Context, dhost string, dport uint32) bool {
log.Println("Accepted forward", dhost, dport)
return true
}),
Addr: ":2222",
Handler: ssh.Handler(func(s ssh.Session) {
io.WriteString(s, "Local forwarding available...\n")
select {}
}),
ChannelHandlers: map[string]ssh.ChannelHandler{
"session": ssh.DefaultSessionHandler,
"direct-tcpip": ssh.DirectTCPIPHandler,
},
}

log.Fatal(server.ListenAndServe())
}

0 comments on commit 0b90efa

Please sign in to comment.