fix: sshsvc服务添加SSH密钥生成逻辑以处理读取失败的情况

This commit is contained in:
TsMask
2025-05-14 14:27:42 +08:00
parent 5d5049805d
commit ad973a813a

View File

@@ -54,12 +54,16 @@ func main() {
// 生成SSH密钥对
privateKeyBytes, err := os.ReadFile(conf.Sshd.PrivateKey)
if err != nil {
log.Fatal("Failed to ReadFile", err)
// ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
// ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" -y
exec.Command("ssh-keygen", "-t", "rsa", "-P", "", "-f", conf.Sshd.PrivateKey, "-N", "", "-y").Run()
log.Fatal("Failed to ReadFile", err)
os.Exit(2)
}
privateKey, err := ssh.ParsePrivateKey(privateKeyBytes)
if err != nil {
exec.Command("ssh-keygen", "-t", "rsa", "-P", "", "-f", conf.Sshd.PrivateKey, "-N", "", "-y").Run()
log.Fatal("Failed to ParsePrivateKey", err)
os.Exit(3)
}