I recently needed to add a tagging step to an automated build, but for some reason the default deploy key that had been configured before was no longer available, possibly due to a GitLab bug.
So I ended up creating a new SSH key pair on the build server and configuring Git-related SSH access to use that new key explicitly.
In the examples below, assume the Git server hostname is gitlab.knktc.com.
First, create a new SSH key pair:
1 | mkdir -p /home/knktc/gitlab_ssh_keys |
In this example, the new private key is stored at:
/home/knktc/gitlab_ssh_keys/id_rsa
Then create or edit the SSH config file under the current user’s home directory:
1 | vim ~/.ssh/config |
Add the following configuration:
1 | Host gitlab.knktc.com |
This means that when connecting to gitlab.knktc.com over SSH, the newly created key will be used.
Finally, test cloning the repository:
1 | git clone git@gitlab.knktc.com:blog/knktc-com.git |
That should work.
For more details about SSH config, see: