如何避免来自 golang 的 "passphrase is too short"
How to avoid "passphrase is too short" from golang
我正在做的是使用
从 golang 程序创建一个 ssh 密钥
exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "\"\"")
但输出失败
exit status 1: Saving key "id_rsa" failed: passphrase is too short (minimum five characters)
如果我在终端中执行命令,它会完美无缺。
Generating public/private rsa key pair.
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:HYixKOtEB42jAr+XNa9uQMZnvmLHa6Sirq+ietWaxzI admin@MacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
| .o . |
|. o... + . |
|.oooo o . . |
|o..++ = . . |
|. o+ B oS . |
| o. = + . |
| .o O o |
|. o E X |
|%*.o Xo. |
+----[SHA256]-----+
完整代码为:
package main
import (
"bytes"
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "\"\"")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
}
您不需要指定空的 -P 属性,只需简单地使用:
exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa")
如果出于任何原因需要指定空 -P
exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "")
另外,在创建 id_rsa 文件之前,请确保它不存在于您正在创建的目录中,否则您将收到退出错误 1:
我正在做的是使用
从 golang 程序创建一个 ssh 密钥exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "\"\"")
但输出失败
exit status 1: Saving key "id_rsa" failed: passphrase is too short (minimum five characters)
如果我在终端中执行命令,它会完美无缺。
Generating public/private rsa key pair.
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:HYixKOtEB42jAr+XNa9uQMZnvmLHa6Sirq+ietWaxzI admin@MacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
| .o . |
|. o... + . |
|.oooo o . . |
|o..++ = . . |
|. o+ B oS . |
| o. = + . |
| .o O o |
|. o E X |
|%*.o Xo. |
+----[SHA256]-----+
完整代码为:
package main
import (
"bytes"
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "\"\"")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return
}
fmt.Println("Result: " + out.String())
}
您不需要指定空的 -P 属性,只需简单地使用:
exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa")
如果出于任何原因需要指定空 -P
exec.Command("ssh-keygen", "-f", "id_rsa", "-t", "rsa", "-P", "")
另外,在创建 id_rsa 文件之前,请确保它不存在于您正在创建的目录中,否则您将收到退出错误 1: