Answer the question
In order to leave comments, you need to log in
How to tell git which ssh key to use when logging in?
Good afternoon!
There is the following task. Some web service has a library of scripts that I want to version.
The solution looks like this:
~/.ssh
. Unfortunately, this solution is not suitable, since the script will be executed on TeamCity agents and I would like to be able to simply put a key on it. ssh -i $path_to_key
~/.ssh/config
would be fine if not for:~/.ssh/id_rsa
~/.ssh/config
This means that it will be problematic to enclose centrally .Answer the question
In order to leave comments, you need to log in
Unexpectedly, the solution was found in the Ansible code
. It is done like this:
#!/bin/sh
if [ -z "$GIT_SSH_OPTS" ]; then
BASEOPTS=""
else</li>
BASEOPTS=$GIT_SSH_OPTS
fi
if [ -z "$GIT_KEY" ]; then
ssh $BASEOPTS "[email protected]"
else
ssh -i "$GIT_KEY" $BASEOPTS "[email protected]"
fi</li>
$ cat ~/.ssh/config
Host my_github
Hostname github.com
IdentityFile ~/.ssh/github.rsa
Create a file ~/.ssh/config. In it for each user:
Host git-as-user1
HostName git.company.com
User git
IdentityFile /home/user1/.ssh/id_rsa.user1
IdentitiesOnly yes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question