我正在尝试通过 GitHub 的 v3 API 添加 ssh 密钥,但它似乎不起作用。
我正在做的是基于此处给出的说明。
更具体地说,我正在使用以下内容:
KEY=$( cat ~/.ssh/id_rsa.pub )
TITLE=${KEY/* }
# the '/* ' above deletes every character in $KEY up to and including the last
# space.
JSON=$( printf '{"title": "%s", "key": "%s"}' "$TITLE" "$KEY" )
TOKEN=$( cat /path/to/tokenfile )
curl -s -d "$JSON" "https://api.github.com/user/keys?access_token=$TOKEN"
当我运行上述内容时,我得到的响应是:
{
"message": "Not Found"
}
...而且,果然,当我签入我的 GitHub 帐户时,$KEY
它不在列出的 ssh-keys 中1。
我究竟做错了什么?
额外细节
如果我只是跑步,我会得到相同的"message": "Not Found"
响应
curl -s "https://api.github.com/user/keys?access_token=$TOKEN"
如果我将-s
上面的内容替换为-i
我看到,确实,返回的状态是404 Not Found
. 然而,返回的状态为
curl -i "https://api.github.com/user/keys"
是401 Unauthorized
。
1我知道访问令牌$TOKEN
很好,因此不是"message": "Not Found"
响应的原因,因为
curl -s "https://api.github.com/user/repos?access_token=$TOKEN"
返回正确的信息,并且
curl -s "https://api.github.com/user/repos"
返回
{
"message": "Requires authentication"
}