Giving devices access to your private Git Repositories using SSH
/A little while back I wrote a blog post telling folks (and future me) how to set up secure sockets so that you can log into remote devices without passwords and create Visual Studio Code remote sessions. Here’s the follow-up, which tells you how to use your SSL keys to give a device access to your private GitHub repositories.
I like to keep my repositories private until I’ve got them kind of sorted. This makes it tricky if I’m deploying to a newly set up remote Raspberry Pi, since it needs GitHub credentials to access private stuff. The best way to solve this problem is to put a copy of the device SSL key onto your GitHub account. It’s easy to do and works a treat. Start by going to GitHub and opening your personal Settings (the one at the top right, not the settings for a particular repository). Then click SSH and GPG keys.
You can see my keys here. Now click New SSH Key. A dialogue will appear asking for two things: the name for the key and the key itself. I use the machine name as the name. You can find the key in the file id_ed25519.pub in the local .ssh folder of your new machine. This file was created when you did ssh-keygen to set up ssh on the machine. Enter the info and close the dialogue. Once you’ve done this you can use the ssh form of git clone to grab private repositories from GitHub.
git clone git@github.com:CrazyRobMiles/custard-cream-camera.git
You’ll need to put your GitHub username and your repository name into the above command. Note that the https way of referring to repositories won’t work.
GitHub will send you an email to tell you when you’ve set one of these up. It also lets you track the last time the key was used. You can remove keys that you are not using.