tim_xyz
tim_xyz

Reputation: 13511

Git push to remote that requires ssh key

Deploys to my remote server fail with a "permission denied" error:

git push prod master

Error

deploy@<IP>: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I can ssh into the server:

$ ssh my_server

Which I have setup in ~/.ssh/config.

Host my_server
    HostName <IP>
    User deploy
    IdentityFile ~/.ssh/my_server_rsa

I previously deployed with password authentication like this.

$ git remote add prod deploy@<IP>:app_prod
$ git push prod master

And then inputted the password when prompted. But now that I've switched to an ssh key, my deploys fail.

So my question is, how do I get git push to use ~/.ssh/config?

I can't figure out how to make this work, and don't know what to google to find an example. Probably missing something super basic here...

Upvotes: 1

Views: 266

Answers (1)

VonC
VonC

Reputation: 1326716

A config file with my_server Host entry means it is a shortcut for:

ssh -i  ~/.ssh/my_server_rsa deploy@<IP>

So to use it, as commented, you need for the remote prod URL to use that my_server config entry:

git remote set-url prod my_server:/path/to/repo
# or
git remote set-url prod ssh://my_server/path/to/repo

Upvotes: 1

Related Questions