我正在尝试如下:
SSHKEY=`cat ~/.ssh/id_rsa.pub`
curl -u username:password -X POST -H "Content-Type: application/json" -d '{"key": "$SSHKEY", "label": "someLabel"}' https://api.bitbucket.org/2.0/users/username/ssh-keys
但它给出了:
{"type": "error", "error": {"fields": {"key": ["That SSH key is invalid."]}, "message": "key: That SSH key is invalid."}}
关于如何使用api将ssh密钥发送到bitbucket的任何想法?
答案 0 :(得分:0)
好吧,我使用python 3脚本使其工作。
#!/usr/bin/python3
import os
import requests, json
url = "https://api.bitbucket.org/2.0/users/userName/ssh-keys"
key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
print(key)
payload = {
"key": key,
"label": "testSSHKey"
}
header = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
response_decoded_json = requests.post(url, auth=requests.auth.HTTPBasicAuth('userName', 'password'), data=payload, headers=header)
response_json = response_decoded_json.json()
print(response_json)