GitLab with ssh keys

Check the official documentation for more information.

Generate ssh keys.

ssh-keygen -t rsa -b 8128 -C "your.email@example.com"

Copy ssh keys to GitLab. Navigate to the SSH Keys tab in your Profile Settings. Paste your key in the Key section and give it a relevant Title.

Start the ssh agent and add your keys to the agent.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/<keyname>

OR

Static config.

vim ~/.ssh/config
-----------------
Host gitlab.com
  IdentityFile /home/yu/.ssh/<keyname>

Configure git options. You could also ommit the --global settings for repository only configuration.

git config --global user.name "<USERNAME>"
git config --global user.email "your.email@example.com"

Clone a repository over ssh.

git clone git@gitlab.com:<USERNAME>/<REPONAME>.git

To update the origin remote repository from http to ssh.

git remote remove origin
git remote add origin git@gitlab.com:<USERNAME>/<REPONAME>.git
git remote show origin