File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "io"
6
+ "log"
7
+ "os"
8
+ "os/exec"
9
+
10
+ "github.com/charmbracelet/ssh"
11
+ )
12
+
13
+ func main () {
14
+ ssh .Handle (func (s ssh.Session ) {
15
+ log .Printf ("connected %s %s %q" , s .User (), s .RemoteAddr (), s .RawCommand ())
16
+ defer log .Printf ("disconnected %s %s" , s .User (), s .RemoteAddr ())
17
+
18
+ pty , _ , ok := s .Pty ()
19
+ if ! ok {
20
+ io .WriteString (s , "No PTY requested.\n " )
21
+ s .Exit (1 )
22
+ return
23
+ }
24
+
25
+ cmd := exec .Command ("powershell.exe" )
26
+ cmd .Env = append (os .Environ (), "SSH_TTY=windows-pty" , fmt .Sprintf ("TERM=%s" , pty .Term ))
27
+ if err := pty .Start (cmd ); err != nil {
28
+ fmt .Fprintln (s , err .Error ())
29
+ s .Exit (1 )
30
+ return
31
+ }
32
+
33
+ // ProcessState gets populated by pty.Start
34
+ for {
35
+ if cmd .ProcessState != nil {
36
+ break
37
+ }
38
+ }
39
+
40
+ s .Exit (cmd .ProcessState .ExitCode ())
41
+ })
42
+
43
+ log .Println ("starting ssh server on port 2222..." )
44
+ if err := ssh .ListenAndServe (":2222" , nil , ssh .AllocatePty ()); err != nil && err != ssh .ErrServerClosed {
45
+ log .Fatal (err )
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments