fix: sshsvc服务添加SSH密钥生成逻辑以处理读取失败的情况
This commit is contained in:
@@ -54,12 +54,16 @@ func main() {
|
|||||||
// 生成SSH密钥对
|
// 生成SSH密钥对
|
||||||
privateKeyBytes, err := os.ReadFile(conf.Sshd.PrivateKey)
|
privateKeyBytes, err := os.ReadFile(conf.Sshd.PrivateKey)
|
||||||
if err != nil {
|
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)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
privateKey, err := ssh.ParsePrivateKey(privateKeyBytes)
|
privateKey, err := ssh.ParsePrivateKey(privateKeyBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
exec.Command("ssh-keygen", "-t", "rsa", "-P", "", "-f", conf.Sshd.PrivateKey, "-N", "", "-y").Run()
|
||||||
log.Fatal("Failed to ParsePrivateKey", err)
|
log.Fatal("Failed to ParsePrivateKey", err)
|
||||||
os.Exit(3)
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user