feat: init commit

This commit is contained in:
2021-07-17 10:16:09 +08:00
parent 428f3935d8
commit 29db055415
5 changed files with 53 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.idea/
# ---> Go # ---> Go
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe

View File

@@ -1,2 +1,6 @@
# simple-ssh-server # simple-ssh-server
uses:
https://github.com/gliderlabs/ssh

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module git.hatter.ink/simple-ssh-server
go 1.13
require github.com/gliderlabs/ssh v0.3.3

14
go.sum Normal file
View File

@@ -0,0 +1,14 @@
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/gliderlabs/ssh v0.3.3 h1:mBQ8NiOgDkINJrZtoizkC3nDNYgSaWtxyem6S2XHBtA=
github.com/gliderlabs/ssh v0.3.3/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

29
main.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import (
"fmt"
"io"
"log"
"strings"
"github.com/gliderlabs/ssh"
gossh "golang.org/x/crypto/ssh"
)
func main() {
ssh.Handle(func(s ssh.Session) {
authorizedKey := gossh.MarshalAuthorizedKey(s.PublicKey())
io.WriteString(s, fmt.Sprintf("\r\n%s\r\n", strings.Repeat("-", 88)))
io.WriteString(s, fmt.Sprintf("public key used by %s:\n", s.User()))
io.WriteString(s, fmt.Sprintf("%v", s.PublicKey()))
io.WriteString(s, fmt.Sprintf("\r\n%s\r\n", strings.Repeat("-", 88)))
s.Write(authorizedKey)
io.WriteString(s, fmt.Sprintf("\r\n%s\r\n", strings.Repeat("-", 88)))
})
publicKeyOption := ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
return true // allow all keys, or use ssh.KeysEqual() to compare against known keys
})
log.Println("Listening :222...")
log.Fatal(ssh.ListenAndServe(":2222", nil, publicKeyOption))
}