I am creating a bash executable, which creates an SSH key, and uploads it to a user's Gitlab account. I am aware of how to create the SSH key via the bash executable:
ssh-keygen -o -f ~/.ssh/id_rsa
and I also know how to retrieve from it, however I don't know how to upload it to a user's Gitlab account.
I have found multiple documentations for uploading a user's SSH to Github however not Gitlab (I assume mostly similar...?). So I would use this for Github
curl -u "USERNAME:PASSWORD" --data "{\"title\": \"TITLE\", \"key\": \"$(cat ~/.ssh/id_rsa.pub)\"}" https://api.github.com/user/keys
and I would make USERNAME
, PASSWORD
, and TITLE
input fields for the user to customize.
I want to say that it would be as simple for Gitlab (I found POST /users/:id/keys
on their API site, but don't know how to implement it as a curl
command), but I don't know how closely related Gitlab and Github are.