Programmatically import users ssh pubkey

Hello all,

I’m running Gitlab CE and I’d like to programmatically import ssh pub keys for my end-users. Is this achievable in any way via API, scripts, backend-tools, etc?

Thanks a lot

Hi,

I’d recommend checking the API docs for any “maintenance” task, you can manage nearly everything through REST calls.

In your case, it is possible to upload an SSH key for an existing user.
https://docs.gitlab.com/ee/api/users.html#add-ssh-key-for-user

User creation can happen before too.
https://docs.gitlab.com/ee/api/users.html#user-creation

Keep in mind that the private token used in the request needs an administrative account.

If you prefer to use a client library in a specific language, the Python API library supports that.
https://python-gitlab.readthedocs.io/en/latest/gl_objects/users.html#ssh-keys

Cheers,
Michael

1 Like