|
|
@ -110,10 +110,10 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func listen(config *ssh.ServerConfig, port int) { |
|
|
|
func listen(config *ssh.ServerConfig, host string, port int) { |
|
|
|
listener, err := net.Listen("tcp", "0.0.0.0:"+com.ToStr(port)) |
|
|
|
listener, err := net.Listen("tcp", host+":"+com.ToStr(port)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
log.Fatal(4, "Fail to start SSH server: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
for { |
|
|
|
for { |
|
|
|
// Once a ServerConfig has been configured, connections can be accepted.
|
|
|
|
// Once a ServerConfig has been configured, connections can be accepted.
|
|
|
@ -148,7 +148,7 @@ func listen(config *ssh.ServerConfig, port int) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Listen starts a SSH server listens on given port.
|
|
|
|
// Listen starts a SSH server listens on given port.
|
|
|
|
func Listen(port int) { |
|
|
|
func Listen(host string, port int) { |
|
|
|
config := &ssh.ServerConfig{ |
|
|
|
config := &ssh.ServerConfig{ |
|
|
|
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { |
|
|
|
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { |
|
|
|
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(key)))) |
|
|
|
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(key)))) |
|
|
@ -180,5 +180,5 @@ func Listen(port int) { |
|
|
|
} |
|
|
|
} |
|
|
|
config.AddHostKey(private) |
|
|
|
config.AddHostKey(private) |
|
|
|
|
|
|
|
|
|
|
|
go listen(config, port) |
|
|
|
go listen(config, host, port) |
|
|
|
} |
|
|
|
} |
|
|
|