Setup ssh key for Git (macOS, Linux)

If you don’t want to authorize yourself all the time on the server, just add an ssh key.


1. Generate an ssh key pair on the client

$ mkdir -m 700 ~/.ssh
$ ssh-keygen -t ed25519 -b 4096 -C {user@domain.com} -f ~/.ssh/{key-name}

2. Add the public key to the Git server

$ cat ~/.ssh/{key-name}.pub

Settings on the server: Bitbucket, GitHub


3. Add the private key to the ssh agent

Temporarily

$ eval $(ssh-agent)
$ ssh-add ~/.ssh/{key-name}

Permanently

$ touch ~/.zprofile
$ echo "ssh-add ~/.ssh/{key-name}" >> ~/.zprofile

(macOS: “.zprofile” and Linux: “.bash_profile”)