2017-12-29 00:45
浏览 119

crypto / ssh ParsePublicKey“短读”错误

In a program I am developing I need a way to add public keys into the authorized_keys file during development, so I am using command line arguments to do so.

I have omitted most of the code, but if you would like to view all of the code, here is the repository, with the problem line being located in main.go on line 20.

b, err := ioutil.ReadFile(os.Args[1])
if err != nil {
    log.Fatalf("Fatal error trying to read new public key file: %s", err)

newAuthorizedKey, err := ssh.ParsePublicKey(b)
if err != nil {
    log.Fatalf("Fatal error trying to parse new public key: %s", err)

The "short read" error comes from the ssh.ParsePublicKey function. The command line argument that I am passing in is the location of a public key to add to the authorized_keys file of this program (e.g. ~/.ssh/ I have ensured that the file is correctly being passed into the program.

I have looked at the source code in hopes of debugging this "short read" error, but I can't figure out what is going on. The location for source code of the ParsePublicKey function in crypto/ssh is located here, and the location of source code of the parseString function, which is what the ParsePublicKey function is using to generate the "short read" error, is located here, also in crypto/ssh.

图片转代码服务由CSDN问答提供 功能建议

在我正在开发的程序中,我需要一种在开发过程中将公共密钥添加到authorized_keys文件中的方法, </ p>

我已经省略了大部分代码,但是如果您想查看所有代码,请使用这是存储库,问题所在的行位于main.go的第20行。</ p>

  b,错误:= ioutil.ReadFile(os.Args [1])
if错误!= nil {
 log.Fatalf(“尝试读取新的公共密钥文件时发生致命错误:%s  “,err)
newAuthorizedKey,err:= ssh.ParsePublicKey(b)
if err!= nil {
 </ code> </ pre> 

“短读”错误来自 ssh.ParsePublicKey </ code>函数。 我要传递的命令行参数是要添加到该程序的authorized_keys文件中的公共密钥的位置(例如〜/ .ssh / </ code>)。 我确保文件已正确传递到程序中。</ p>

我已经查看了源代码,希望调试此“短读”错误,但我不知道 到底是怎么回事。 crypto / ssh </ code>中 ParsePublicKey </ code>函数的源代码位置位于此处,以及 parseString </ code>函数的源代码位置,即 ParsePublicKey </ code >函数用于生成“短读”错误,位于此处,也在 crypto / ssh </ code>中。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题