This instruction is small, obvious and simple. Open a terminal, enter the command:
ssh-keygen -t rsa
Hooray, the key is created!
cat ~/.ssh/id_rsa.pub
Thus, the contents of the public key are displayed. If you work with GitLab, then inside you just copy the contents to Account – Settings – SSH keys – Add an SSH key.
If you need console copying, then set ssh-copy-id and copy the public key to the remote server:
brew install ssh-copy-id ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
If you work through a non-standard port, then write:
ssh-copy-id -p portnum user@host