SSH Config for GitLab

Configure SSH access to GitLab with a dedicated identity file. Includes Host alias setup, ed25519 key recommendation, and AddKeysToAgent for convenience.

Basic Config

Detailed Explanation

Configuring SSH for GitLab

GitLab supports SSH authentication for Git operations, and setting up a config entry makes the process seamless. The configuration is very similar to GitHub but targets gitlab.com (or your self-hosted GitLab instance).

Example Config

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gitlab
  IdentitiesOnly yes
  AddKeysToAgent yes

Self-Hosted GitLab

If you use a self-hosted GitLab instance, adjust the Host and HostName accordingly:

Host gitlab-internal
  HostName gitlab.mycompany.com
  User git
  Port 2222
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes

Port Customization

Some organizations run their GitLab SSH on a non-standard port (commonly 2222 or 443 to bypass firewall restrictions). The Port directive handles this transparently, so you can still use git clone gitlab-internal:group/project.git without specifying the port each time.

Key Type Recommendation

GitLab recommends ed25519 keys for their security and performance. If your system does not support ed25519, RSA with at least 4096 bits is an acceptable alternative.

Adding the Key

Copy the public key to your clipboard and add it at GitLab > Preferences > SSH Keys:

cat ~/.ssh/id_ed25519_gitlab.pub | pbcopy    # macOS
cat ~/.ssh/id_ed25519_gitlab.pub | xclip     # Linux

Use Case

Teams and individual developers who host code on GitLab.com or self-hosted GitLab instances and want streamlined SSH authentication.

Try It — SSH Config Generator

Open full tool