Skip to content

Commit 401d120

Browse files
committed
Add localforward example
1 parent ef7b36b commit 401d120

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"io"
5+
"log"
6+
7+
"github.com/gliderlabs/ssh"
8+
)
9+
10+
func main() {
11+
log.Println("starting ssh server on port 2222...")
12+
13+
server := ssh.Server{
14+
LocalPortForwardingCallback: ssh.LocalPortForwardingCallback(func(ctx ssh.Context, dhost string, dport uint32) bool {
15+
log.Println("Accepted forward", dhost, dport)
16+
return true
17+
}),
18+
Addr: ":2222",
19+
Handler: ssh.Handler(func(s ssh.Session) {
20+
io.WriteString(s, "Remote forwarding available...\n")
21+
select {}
22+
}),
23+
ChannelHandlers: map[string]ssh.ChannelHandler{
24+
"session": ssh.DefaultSessionHandler,
25+
"direct-tcpip": ssh.DirectTCPIPHandler,
26+
},
27+
}
28+
29+
log.Fatal(server.ListenAndServe())
30+
}

0 commit comments

Comments
 (0)