Last active
September 24, 2025 12:14
-
-
Save UNC1739/1aa25e5a810b13d531a320563d2ebafc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
| "crypto/ed25519" | |
| "crypto/rand" | |
| "errors" | |
| "log" | |
| "net" | |
| "golang.org/x/crypto/ssh" | |
| ) | |
| func main() { | |
| _, priv, _ := ed25519.GenerateKey(rand.Reader) | |
| signer, _ := ssh.NewSignerFromKey(priv) | |
| cfg := &ssh.ServerConfig{ | |
| PasswordCallback: func(conn ssh.ConnMetadata, password []byte) (*ssh.Permissions, error) { | |
| log.Printf("SSH login attempt: user=%s pass=%s from=%s", | |
| conn.User(), string(password), conn.RemoteAddr()) | |
| return nil, errors.New("permission denied") | |
| }, | |
| ServerVersion: "SSH-2.0-OpenSSH_8.9p1", | |
| } | |
| cfg.AddHostKey(signer) | |
| l, _ := net.Listen("tcp", "0.0.0.0:22") | |
| log.Println("Listening on 0.0.0.0:22") | |
| for { | |
| conn, _ := l.Accept() | |
| go func(c net.Conn) { | |
| defer c.Close() | |
| ssh.NewServerConn(c, cfg) | |
| }(conn) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment