1.EC2側
EC2にSSH接続後
EC2
cat .ssh/id_rsa.pub
鍵がない場合は作成する
EC2
ssh-keygen -t rsa
cat .ssh/id_rsa.pub
表示された文字列をコピーしておく
2.GitLab側
Deploy Key登録
プロジェクトのSettings > Repository

Deploy Keyを登録する
Title : 適当
Key : EC2でコピーしたもの(id_rsa.pubの中身)
3.EC2側
クローンする
EC2
git clone {Gitlabのプロジェクトでcloneボタンを押したら出てくるgit@~}
※ 別のプロジェクトも同じEC2にクローンする場合(Gitlab側)
Gitlabで登録済みのDeploy Keyを有効化する
プロジェクト > Settings > Repository > Deploy Key

有効化前


有効化後

クローンする(EC2側)
EC2
git clone {Gitlabのプロジェクトでcloneボタンを押したら出てくるgit@~}