L
L
Lev K2017-03-27 16:36:37
git
Lev K, 2017-03-27 16:36:37

How to use multiple keys of one server in git?

There is an already generated key (and added to the repository)
if the key name is changed to id_rsa (standard, but NOT created with that name), then git works like a clock, but if I change it to a different name (both public and private) in this case, id_rsa in general no and there is .ssh/config, in which:

Host host_h1
 HostName bitbucket.org
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/h1
 
Host host_h2
 HostName bitbucket.org
 User jobsearch
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/h2

Then when I try to work with git I get:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I rummaged through the net, I didn’t find a clear explanation, why everyone does it like this:
git -vT [email protected]
I didn’t quite understand why this was, I got the same Permission denied (publickey), but in general I don’t think that I need it it is only necessary to work with the repository.
Do not tell me what I'm doing wrong
PS this is necessary for the fact that there are 2 projects on the server, and when I try to push the public key of the 1st project into the 2nd repository, I get an error on bitbucket that such a key already exists. Probably on all basis drives away.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry MiksIr, 2017-03-27
@Leffken

Bitbucket, as well as github, use a key to determine the username. Therefore, when SSH connects to these servers, the User is always the same - git. Those. you need to remove User jobsearch (or replace it with User git, and in the first case you can put User git).
Further, in order for ssh to choose different keys, when connecting, you need to specify not the name of the original host, but the name of the host alias (the one in Host). Those. git clone host_h2:/... and git clone host_h1:/...., well, or git clone [email protected]_h2:/... and git clone [email protected]_h1:/.... if User was removed from the config.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question