bash upload github api bash curl upload key不起作用

时间:2017-02-19 22:01:46

标签: bash curl github

编辑:我发现这是一个很好的答案,所以这可能会被标记为重复:https://stackoverflow.com/a/31214819/123594

我尝试通过bash / curl将新生成的部署密钥上传到github

这里有我所拥有的:( $ 1是我的回购名称,$ 2是我的密钥名称的后缀)

TOKEN=`cat /path/to/.github_token`
ssh-keygen -b 2048 -t rsa -f /path/to/key/id_rsa-www_$2 -q -N ""
KEY=`cat ~/projects/automatem/ansible/roles/accounts/templates/id_rsa-www_$2.pub`
echo $KEY
curl -u "myusername:$TOKEN" https://api.github.com/repos/jochendaum/$1/keys -d '{"name":"AUS1","key":"$KEY","read_only":true}'

作为输出我得到:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3rVUbDbhhHCD2q00T29UJRbMqbDdXOq8qwUlY/gOtvzxCu20nQHvGXG4L2FLWffO8V5TQH+e5Ei0G2TDfbjgiYH/BBBEd+agkZf6VHfWmOTG93D55Sse6LoVJNgXu1RICM3zS0CPQ31b05UUIw6AFjesntIh8EoaeftSm99CCxgLT3bRkSWkfSAng6VD6EwT1od+RMXxqOMpyJv0BeJaOELjJM8AAIIbjrcPaprAG3OixtJoYdBnUyK14srdmUjKmnJMFcrlFRPphzTnpjXZAFVIK1j7+Mh9UnNIKE5nlBL5Y5YtUkyy7ixIM/dCfu9tAyxufKjGz23Ug111WTmzB jochen@autodesktop2

{

  "message": "Validation Failed",
  "errors": [
    {
      "resource": "PublicKey",
      "code": "custom",
      "field": "key",
      "message": "key is invalid. It must begin with 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', or 'ecdsa-sha2-nistp521'. Check that you're copying the public half of the key"
    }
  ],
  "documentation_url": "https://developer.github.com/v3/repos/keys/#create"
}

当密钥通过curl发送时,好像有什么东西被切断了

1 个答案:

答案 0 :(得分:0)

除了你似乎使用的奇怪路径,但它可能只是在你身边掩盖不好,Bash不会在单引号内扩展任何东西。