Member-only story
How to deal with Multiple SSH Keys in GitLab
A practical example of how to work with multiple SSH keys in GitLab
2 min readDec 11, 2024
If you use multiple SSH keys to access different repositories or accounts (e.g., work, personal, or provided by others), you can configure them in the ~/.ssh/config
file. Here's a detailed example and explanation:
Example Scenario
You have:
- A personal SSH key:
~/.ssh/id_ed25519_personal
. - A work SSH key:
~/.ssh/id_ed25519_work
. - A project-specific SSH key someone gave you:
~/.ssh/id_ed25519_project
.
You need to configure SSH to:
- Use your personal key for repositories on your personal GitLab account.
- Use your work key for your company’s GitLab repositories.
- Use the project-specific key for accessing the shared project.
Configuration File Structure
The SSH configuration file (~/.ssh/config
) allows you to define custom rules for which key to use for different hosts or repositories.
Here’s how the configuration might look:
# Personal GitLab account
Host gitlab-personal
HostName gitlab.com
User git…