Add a GitLab SSH key on a machine
Step 1: Check for existing SSH keys
Check if you already have an SSH key:
ls -al ~/.ssh
Look for files like id_rsa, id_ed25519, or id_ecdsa.
Step 2: Generate a new SSH key (if needed)
If you don’t have an SSH key, generate one:
ssh-keygen -t ed25519 -C "[email protected]"
Or if your system doesn’t support Ed25519:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Press Enter to accept the default file location (~/.ssh/id_ed25519 or ~/.ssh/id_rsa), and optionally set a passphrase.
Step 3: Copy your public key
Display and copy your public key:
cat ~/.ssh/id_ed25519.pub
Or if you used RSA:
cat ~/.ssh/id_rsa.pub
Copy the entire output (starts with ssh-ed25519 or ssh-rsa).
Step 4: Add the key to GitLab
- Go to GitLab → Profile → SSH Keys (or
https://gitlab.com/-/profile/keys) - Paste your public key into the “Key” field
- Give it a title (e.g., “My Linux Machine”)
- Click “Add key”
Step 5: Test the connection
Test the connection to GitLab:
ssh -T [email protected]
You should see a welcome message like: Welcome to GitLab, @username!
Optional: Start SSH agent (if needed)
If you’re using a passphrase and want to avoid typing it every time:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
(Or ~/.ssh/id_rsa if you used RSA)
Note: If you use a self-hosted GitLab instance, replace gitlab.com with your GitLab server’s hostname in step 5.







