2
votes

When i run this on mac, everything is ok :

git clone [email protected]:my_project

When i run it at home and copied my home id_rsa.pub key to ssh project in authorized_keys , ssh connection is ok, but cloning git repo requires password, why?

Full steps to reproduce:

git config --global user.name 'User Surname'
git config --global user.email '[email protected]'
ls -al ~/.ssh # shows nothing 
ssh-keygen -t rsa -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
sudo apt-get install xclip
xclip -sel clip < ~/.ssh/id_rsa.pub

Paste id_rsa.pub from cliboard to github account -> settings -> ssh keys -> add and press enter, it added successfully

ssh -T [email protected]

Hi user! You've successfully authenticated, but GitHub does not provide shell access. Paste the same id_rsa.pub to evernote

From my working mac, copy it from evernote, and connect to ssh:

ssh [email protected]
ee ~/.ssh/authorized_keys

Paste id_rsa from evernote in end of file and save file.

cd my-rails-app/repo
git ls-remote

Copy part of first string from stdout:

From [email protected]:my_project

Connect to ssh from home asus

ssh [email protected]

everything is ok

git clone [email protected]:my_project

-> required password

1
What are the exact sequence of steps your run? - Anshul Goyal
I added full steps to reproduce to the main question above - user1028432
I had this problem because a program i had installed, changed the ~/.ssh default location. You can see this by running in Git Bash the command ssh-keygen. If your default location is not /c/Users/<your user name>/.ssh/id_rsa than you shoud look at Enviromental variables to see if some variable is changing .ssh location. - Ovidiu Uşvat

1 Answers

1
votes

When the ssh keys are not configured correctly, then the git clone "git@{host}" tries to connect to {host} as user "git", hence the request for a password. So you'll need to fix/troubleshoot the ssh keys issue.

Do your work/mac/home computers have different user-names? Are you using gitolite, gitlab, etc? How was the ssh.pub configured in git?

Note that if (1) "when I run this on my mac, everything is ok", then (2) "run it at home and copied my home id-rsa pub key to ssh project in authorized-keys", this doesn't make sense for git. You've only enabled ssh login as "you", not as "git". The easiest solution is to copy your private ssh key "from your mac" and copy it into your "home" computer's ~/.ssh directory. Otherwise, you just need to add your home computer to your git server's configuration as a new user.