Created
March 6, 2020 05:14
-
-
Save HwDhyeon/3a0092f2a915612fad7e3950edac7844 to your computer and use it in GitHub Desktop.
ssh 모듈을 이용해 ssh 서버 생성하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"time" | |
"github.com/gliderlabs/ssh" | |
) | |
func main() { | |
MaxTimeout := time.Second * 20 | |
IdleTimeout := time.Second * 10 | |
ssh.Handle(func(s ssh.Session) { | |
i := 0 | |
for { | |
i++ | |
select { | |
case <-time.After(time.Second): | |
continue | |
case <-s.Context().Done(): | |
return | |
} | |
} | |
}) | |
server := &ssh.Server{ | |
Addr: ":22", | |
MaxTimeout: MaxTimeout, | |
IdleTimeout: IdleTimeout, | |
} | |
err := server.ListenAndServe() | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment