Checkout from Gitlab with different SSH key than log into server
Opened this issue · 3 comments
Konafets commented
I deploy from my local machine to a server using SSH Key A. On the server I created a SSH Key B which I uploaded at gitlab.com. I can clone a Repository with that key.
However, when I deploy the application it failed to checkout with
bash --login -c '/usr/local/bin/git clone "git@gitlab.com:username/app.git" "/var/www/virtual/username/app/releases/20170113165751" --branch="develop" --depth="1"'
[username@example.com] (staging) Cloning into '/var/www/virtual/username/app/releases/20170113165751'...
[username@example.com] (staging) Permission denied (publickey).
[username@example.com] (staging) fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
staging/0 |===> An error occured: "Unable to clone the repository", while running:
Cloning into '/var/www/virtual/username/app/releases/20170113165751'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
What should I do to make this working.
dmaphy commented
I'd personally suggest to write some lines of SSH configuration which decides which key to use
Konafets commented
Hi @dmaphy,
I think I don't understand. Where should this config go and how to decide which config should be used. Can you give a short example?
dmaphy commented
Hi,
basically you'd do something like this in you ~/.ssh/config
:
Host gitlab.somewhere.com
User git
IdentityFile ~/.ssh/my_gitlab_deploy.key
Host some_other_host.com
User myusername
Port 22
IdentityFile ~/.ssh/another_ssh.key
See man ssh_config
for more detailed information.