重新整理思路3
This commit is contained in:
25
srv/internal/resource/ssh.go
Normal file
25
srv/internal/resource/ssh.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"Crimson-Gatekeeper/internal/utils"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func getSshEnv(name string) *ssh.Client {
|
||||
sshCfg := cfg.server.sshPoint[name]
|
||||
if sshCfg == nil {
|
||||
return nil
|
||||
}
|
||||
clientCfg := &ssh.ClientConfig{
|
||||
User: sshCfg.user,
|
||||
Auth: []ssh.AuthMethod{
|
||||
ssh.Password(sshCfg.passwd),
|
||||
},
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
}
|
||||
client, err := ssh.Dial("tcp", sshCfg.host+strconv.Itoa(sshCfg.port), clientCfg)
|
||||
utils.PaincEro(err, "建立 SSH 隧道失败,程序中止")
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user