ssh: load more host key formats than rsa
This commit is contained in:
parent
d69f2f27ee
commit
650c913930
@ -133,6 +133,7 @@ func setUserPass(user, passwordHash string) {
|
|||||||
p := strings.Split(line, ":")
|
p := strings.Split(line, ":")
|
||||||
if len(p) < 2 || p[0] != user {
|
if len(p) < 2 || p[0] != user {
|
||||||
buf.WriteString(line)
|
buf.WriteString(line)
|
||||||
|
buf.WriteByte('\n')
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
ssh.go
27
ssh.go
@ -23,18 +23,29 @@ func startSSH(cfg *config.Config) {
|
|||||||
PublicKeyCallback: sshCheckPubkey,
|
PublicKeyCallback: sshCheckPubkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
pkBytes, err := os.ReadFile("/id_rsa") // TODO configurable
|
hostKeyLoaded := false
|
||||||
if err != nil {
|
|
||||||
fatalf("ssh: failed to load private key: %v", err)
|
for _, format := range []string{"rsa", "dsa", "ecdsa", "ed25519"} {
|
||||||
|
pkBytes, err := os.ReadFile("/id_" + format)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("ssh : failed to load %s host key: %v", format, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
pk, err := ssh.ParsePrivateKey(pkBytes)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("ssh: failed to parse %s host key: %v", format, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sshConfig.AddHostKey(pk)
|
||||||
|
hostKeyLoaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
pk, err := ssh.ParsePrivateKey(pkBytes)
|
if !hostKeyLoaded {
|
||||||
if err != nil {
|
fatalf("ssh: failed to load any host key")
|
||||||
fatalf("ssh: failed to parse private key: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sshConfig.AddHostKey(pk)
|
|
||||||
|
|
||||||
sshBind := ":22" // TODO configurable
|
sshBind := ":22" // TODO configurable
|
||||||
listener, err := net.Listen("tcp", sshBind)
|
listener, err := net.Listen("tcp", sshBind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user