Step 1: Generate the key
ssh-keygen -t ed25519 -C "your_email@example.com"
Optional: To specify custom names of the key file
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/my_custom_name
Step 2: Start the ssh-agent
eval "$(ssh-agent -s)"
Step 3: Add your key to ssh-agent
ssh-add ~/.ssh/id_ed25519
or if use specified custom name
ssh-add ~/.ssh/my_custom_name
Step 4: Copy your public key
cat ~/.ssh/id_ed25519.pub
This will display something like:
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl3dIeudNqd0DPMRD6OIh65A9gg2GPow5Fzy9Hvd1HS your_email@example.com
Step 5: Add to GitLab or Github
- Copy the entire output from the previous command
- Go to https://gitlab.com/-/user_settings/ssh_keys/
- Select Add new key
- Paste the key into the "Key" field
- Give it a title (e.g., "Production Server")
- Click "Add key"
Step 6: Test the connection
ssh -T git@gitlab.com
You should see: Welcome to GitLab, @yourusername!
Top comments (0)