Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 通过curl添加SSH密钥:无法生成指纹_Git_Bash_Curl_Gitlab_Ssh Keys - Fatal编程技术网

Git 通过curl添加SSH密钥:无法生成指纹

Git 通过curl添加SSH密钥:无法生成指纹,git,bash,curl,gitlab,ssh-keys,Git,Bash,Curl,Gitlab,Ssh Keys,我正在编写一个bash脚本,它将向内部Gitlab服务器添加一个SSH密钥。代码如下: userToken=$(curl http://gitserver/api/v3/session --data 'login=*****&password=****' | jq '.private_token') userToken=$(echo "$userToken" | tr -d '"') # Below key is for testing, will use output of cat

我正在编写一个bash脚本,它将向内部Gitlab服务器添加一个
SSH密钥。代码如下:

userToken=$(curl http://gitserver/api/v3/session --data 'login=*****&password=****' | jq '.private_token')
userToken=$(echo "$userToken" | tr -d '"')

# Below key is for testing, will use output of cat ~/.ssh/id_rsa.pub later on
sshKey="ssh-rsa AA*********L ****@***com"

curl --data "private_token=$userToken&title=keyName&key=$sshKey" "http://gitserver/api/v3/user/keys"
但我得到的回应是:

{
  "message": {
    "fingerprint": [
      "cannot be generated"
    ]
  }
}
但是,当我手动将同一把钥匙插入网络浏览器时,一切都很正常


那么我做错了什么?我是否遗漏了一个选项?

看起来SSH公钥中的空格没有正确转义。某些字符不能在POST数据字符串中使用,包括空格

尝试使用
curl--data urlencode
而不是
curl--data
来自动编码POST数据。

OP here

与此同时,我将服务器更新为8.8版,并对
curl
代码做了一些更改,现在它的工作非常出色:

curl -X POST -F "private_token=${userToken}" -F "title=${sshName}" -F "key=${sshKey}" "${gitServer}/user/keys"

以防万一将来有人需要它…

简短的问题:curl/GitLab能处理post字符串中的空格吗,或者你需要用url编码你的post数据吗?您可以尝试使用
curl--data urlencode
而不是
curl--data
@ErikE.Lorenz。看起来这可能是问题所在,并且可以解决!唯一的问题。。。我从这个项目中被带走了。但是我把这个信息传递给了负责人(尽管他没有时间尝试)。但既然这看起来可以解决问题,你可以创建一个正式的答案,这样我就可以接受了。