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
![スクリーンショット 2020-08-11 12.22.31.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F125006%2F5cd5b38f-90a1-5d59-d765-4d0cbc28a80c.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=bfcf551d2a33760d08142de17bc9e0e0)
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
![スクリーンショット 2020-08-11 12.06.28.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F125006%2F1e3679ad-d952-5edb-3b1b-6408f34c8d39.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=6a3c3df58abb8e0be143aa7ad99cf247)
有効化前
![スクリーンショット 2020-08-11 12.34.03.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F125006%2F59bda0c2-8486-01ee-8e90-e542fc41a87a.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=275774e9ca2303f70fb95cad2f8558e2)
![スクリーンショット 2020-08-11 12.34.20.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F125006%2F1c84be6c-c5e1-cdc2-89f3-3802446ed07a.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=2701170b752f9bae833d0582562092e1)
有効化後
![スクリーンショット 2020-08-11 12.31.52.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F125006%2Fb089d66d-a2f1-53b7-29b4-ffe11bfbeeea.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=765aca631cec41e7a4bc0db394b87f35)
クローンする(EC2側)
EC2
git clone {Gitlabのプロジェクトでcloneボタンを押したら出てくるgit@~}