SSH Keys is an access credential used in the Secure Shell (SSH) protocol to authenticate and establish an encrypted communication channel between a client and a remote server

Establish connection between Git server

The following use Shell commands on Terminal

Client side

Create SSH key, type Ed25519, using email or username as the comment and paste it to file inside folder ~/.ssh (link Users/chiffonng/.ssh/)

ssh-keygen -t ed25519 -C "label" -f ~/.ssh/id_gitlab

Add passphrase as prompted

Add the public key to the agent, using Apple keychain (add identity)

ssh-add --apple-use-keychain ~/.ssh/id_gitlab

Open file

open ~/.ssh/config

then add configurations to ~/.ssh/config

# GitHub
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_github
 
# GitLab  
Host gitlab.lrz.de
  HostName gitlab.lrz.de
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_gitlab
  IdentitiesOnly yes

Server side

Copy the public key to upload to the remote server like GitLab and GitHub

pbcopy < ~/.ssh/id_gitlab.pub

Verify the fingerprint Github Ed25519 should have key fingerprint SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU after typing

ssh -T git@github.com

We can obtain the key fingerprint by running first-time connection.

ssh -T git@gitlab.lrz.de

Update the SSH host key entry in ~/.ssh/known_hosts file with the correct fingerprint. Or we can find all server public host keys by running, and copy to ~/.ssh/known_hosts

ssh-keyscan gitlab.lrz.de