DEV Community

Cover image for Complete SSH Key Setup
Ajmal Muhammed
Ajmal Muhammed

Posted on

Complete SSH Key Setup

Step 1: Generate the key

ssh-keygen -t ed25519 -C "your_email@example.com"

Enter fullscreen mode Exit fullscreen mode

Optional: To specify custom names of the key file

ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/my_custom_name
Enter fullscreen mode Exit fullscreen mode

Step 2: Start the ssh-agent

eval "$(ssh-agent -s)"

Enter fullscreen mode Exit fullscreen mode

Step 3: Add your key to ssh-agent

ssh-add ~/.ssh/id_ed25519

Enter fullscreen mode Exit fullscreen mode

or if use specified custom name

ssh-add ~/.ssh/my_custom_name

Enter fullscreen mode Exit fullscreen mode

Step 4: Copy your public key

cat ~/.ssh/id_ed25519.pub

Enter fullscreen mode Exit fullscreen mode

This will display something like:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl3dIeudNqd0DPMRD6OIh65A9gg2GPow5Fzy9Hvd1HS your_email@example.com

Enter fullscreen mode Exit fullscreen mode

Step 5: Add to GitLab or Github

  1. Copy the entire output from the previous command
  2. Go to https://gitlab.com/-/user_settings/ssh_keys/
  3. Select Add new key
  4. Paste the key into the "Key" field
  5. Give it a title (e.g., "Production Server")
  6. Click "Add key"

Step 6: Test the connection

ssh -T git@gitlab.com

Enter fullscreen mode Exit fullscreen mode

You should see: Welcome to GitLab, @yourusername!

Top comments (0)