I'm setting up a new Ubuntu (18.04) server and noticed during install that I could import public keys from github. I've now finished setup and would like to create some more users. It seems ideal to keep importing their public keys from github if possible. Is there a way to trigger that feature of importing keys from a public github profile for a user outside of the installation process?


A short while after posting the question I found the answer. There is a special command ssh-import-id which can import ssh keys. The man page for ssh-import-id explains it quite well. It's hosted as ssh-import-id on launchpad as well.

Basic usage:

# import keys from github
ssh-import-id-gh <username>

I hope this helps others.


GitHub provides this via an API Endpoint that you can download and parse. Unfortunately for us, this does return objects in a JSON format, so it's a bit hard to parse at times (especially in the shell).

Fortunately for us, there's another endpoint to get a user's public SSH keys:


You can use this with wget to download and append keys really simply and without any parsing:

wget -O - https://github.com/myuser.keys >> /home/myuser/.ssh/authorized_keys

Note that in order to use this command, you will need write permissions to that user's homedir. You may optionally use tee -a as well, which would be easier if privileges aren't guaranteed:

wget -O - https://github.com/myuser.keys | sudo tee -a /home/myuser/.ssh/authorized_keys
  • Thanks, great solution. I found ssh-import-id which seems to do something similar into a command with some validation and error checking. – greggles May 22 '19 at 19:25
  • Confirmed this works with 20.04 server Installer Selected launchpad, instead of github, but this supports both. – Wolftales Jul 2 '20 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.