This is for myself to remind how I troubleshoot and someone who has trouble setup the git on raspberry pi.
For those of you who want just answer, jump to the solution.
1. Issue
I was trying to clone my react portfolio website project on raspberry pi to host myself. I had permission issues while cloning.
2. Tried
I realized I forgot to add ssh key for my rpi on github, so I was searching the ssh key on my rpi under ~/.ssh folder. However, there was no specific ssh keys under that folder, but some other files that I made config while setting up the rpi.
So, I was searching again, and I found ssh keys under etc/ssh folder.
If you try type below command, you will see github will looking for ssh keys in ~/.ssh this folder.
ssh -vT [email protected]
On the screenshot above, you can see -1 at the end is status as I searched. Meaning, not found.
So, I add one of the ssh keys to github and copied and paste the ssh keys from etc/ssh folder to ~/.ssh folder. Make sure using command line with sudo to copy/paste the private key. If not, will give you permission denied.
After done everything, I tried clone the repo again. Still get same permission denied issue. but this time having something like below. (forgot to get screenshot.)
Load key "/root/.ssh/id_rsa": bad permissions
[email protected]: Permission denied (publickey).
It was loading key now, but still get permission denied. So, I tried with multiple different ssh keys like rsa, ecdsa, and ed25519. However, all failed.
3. Solution
Honestly, I don’t remember I generated those ssh keys or not, and why they are in the other folder instead as usual under ~/.ssh folder. So, I just decided to generate new ssh keys.
ssh-keygen -t rsa -C "[email protected]"
then, you will be asked to type in things like….
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
then, enter id_rsa for the first request, and password or just hit enter if you don’t need password.
now, add the public key to github.
Yay!! now I could successfully clone!!!
4. Reference
- Raspberry Pi Guide 4.3 Git by mlagerberg
- Fab Academy Raspberry Pi Tips Configure Github to RaspPi by Tatsuro Homma
- Setting up SSH Keys for GitHub Access by Gary Woodfine
Hope you solved your issue!