Reputation: 141
I'm using Raspbian.
I did successfully added the key and I can clone a private repo with ssh auth manually, using the command git clone [email protected]:USER/repo.git
.
Here is how I set it up:
ssh-keygen -t rsa -b 4096 -C “email”
eval "$(ssh-agent -s)"
ssh-add -k ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub
However, if I try to run git clone command through a bash script, I get Permission denied (publickey).
I'm running the script as "pi", with sudo. The script starts with #! /bin/bash
and whoami
(on the script) returns root
, instead of "pi".
Could someone help me out, please?
Thanks!
Upvotes: 1
Views: 3475
Reputation: 848
SSH attemps to read the keys from $HOME/.ssh
. Since you are running as root
, the script most likely fails to find anything under /home/root/.ssh
.
The fix? Try sudo -E
, which preserves the environment variables. For more info, consult sudo(8).
Upvotes: 2