Linux

Linux Git 연결 - Amazon EC2

쓱은감자 2024. 5. 1. 14:55

개요

AWS EC2를 생성 후 git의 코드를 배포하기 위해서는 ec2에 git을 연결하여 코드를 가져와야 한다. 이를 처리하기 위해 ec2 서버에 git을 연결하는 방법을 설명한다.

Linux Git 연결

[ec2-user@ip-172-31-10-164 ~]$ sudo yum install git
Last metadata expiration check: 1 day, 1:37:34 ago on Sun Mar 10 11:20:00 2024.
Dependencies resolved.
==============================================================================================================================================================================================================
 Package                                            Architecture                             Version                                                      Repository                                     Size
==============================================================================================================================================================================================================
Installing:
 git                                                x86_64                                   2.40.1-1.amzn2023.0.1                                        amazonlinux                                    57 k
Installing dependencies:
 git-core                                           x86_64                                   2.40.1-1.amzn2023.0.1                                        amazonlinux                                   4.3 M
 git-core-doc                                       noarch                                   2.40.1-1.amzn2023.0.1                                        amazonlinux                                   2.6 M
 perl-Error                                         noarch                                   1:0.17029-5.amzn2023.0.2                                     amazonlinux                                    41 k
 perl-File-Find                                     noarch                                   1.37-477.amzn2023.0.6                                        amazonlinux                                    26 k
 perl-Git                                           noarch                                   2.40.1-1.amzn2023.0.1                                        amazonlinux                                    45 k
 perl-TermReadKey                                   x86_64                                   2.38-9.amzn2023.0.2                                          amazonlinux                                    36 k
 perl-lib                                           x86_64                                   0.65-477.amzn2023.0.6                                        amazonlinux                                    15 k

Transaction Summary
==============================================================================================================================================================================================================
Install  8 Packages

Total download size: 7.1 M
Installed size: 34 M
Is this ok [y/N]: y
Downloading Packages:
(1/8): perl-TermReadKey-2.38-9.amzn2023.0.2.x86_64.rpm                                                                                                                        612 kB/s |  36 kB     00:00
(2/8): perl-lib-0.65-477.amzn2023.0.6.x86_64.rpm                                                                                                                              242 kB/s |  15 kB     00:00
(3/8): git-2.40.1-1.amzn2023.0.1.x86_64.rpm                                                                                                                                   824 kB/s |  57 kB     00:00
(4/8): perl-File-Find-1.37-477.amzn2023.0.6.noarch.rpm                                                                                                                        1.6 MB/s |  26 kB     00:00
(5/8): perl-Git-2.40.1-1.amzn2023.0.1.noarch.rpm                                                                                                                              2.8 MB/s |  45 kB     00:00
(6/8): perl-Error-0.17029-5.amzn2023.0.2.noarch.rpm                                                                                                                           2.7 MB/s |  41 kB     00:00
(7/8): git-core-2.40.1-1.amzn2023.0.1.x86_64.rpm                                                                                                                               46 MB/s | 4.3 MB     00:00
(8/8): git-core-doc-2.40.1-1.amzn2023.0.1.noarch.rpm                                                                                                                           24 MB/s | 2.6 MB     00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          27 MB/s | 7.1 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                      1/1
  Installing       : git-core-2.40.1-1.amzn2023.0.1.x86_64                                                                                                                                                1/8
  Installing       : git-core-doc-2.40.1-1.amzn2023.0.1.noarch                                                                                                                                            2/8
  Installing       : perl-Error-1:0.17029-5.amzn2023.0.2.noarch                                                                                                                                           3/8
  Installing       : perl-File-Find-1.37-477.amzn2023.0.6.noarch                                                                                                                                          4/8
  Installing       : perl-lib-0.65-477.amzn2023.0.6.x86_64                                                                                                                                                5/8
  Installing       : perl-TermReadKey-2.38-9.amzn2023.0.2.x86_64                                                                                                                                          6/8
  Installing       : perl-Git-2.40.1-1.amzn2023.0.1.noarch                                                                                                                                                7/8
  Installing       : git-2.40.1-1.amzn2023.0.1.x86_64                                                                                                                                                     8/8
  Running scriptlet: git-2.40.1-1.amzn2023.0.1.x86_64                                                                                                                                                     8/8
  Verifying        : git-2.40.1-1.amzn2023.0.1.x86_64                                                                                                                                                     1/8
  Verifying        : perl-TermReadKey-2.38-9.amzn2023.0.2.x86_64                                                                                                                                          2/8
  Verifying        : perl-lib-0.65-477.amzn2023.0.6.x86_64                                                                                                                                                3/8
  Verifying        : git-core-2.40.1-1.amzn2023.0.1.x86_64                                                                                                                                                4/8
  Verifying        : perl-File-Find-1.37-477.amzn2023.0.6.noarch                                                                                                                                          5/8
  Verifying        : perl-Git-2.40.1-1.amzn2023.0.1.noarch                                                                                                                                                6/8
  Verifying        : perl-Error-1:0.17029-5.amzn2023.0.2.noarch                                                                                                                                           7/8
  Verifying        : git-core-doc-2.40.1-1.amzn2023.0.1.noarch                                                                                                                                            8/8

Installed:
  git-2.40.1-1.amzn2023.0.1.x86_64                     git-core-2.40.1-1.amzn2023.0.1.x86_64          git-core-doc-2.40.1-1.amzn2023.0.1.noarch            perl-Error-1:0.17029-5.amzn2023.0.2.noarch
  perl-File-Find-1.37-477.amzn2023.0.6.noarch          perl-Git-2.40.1-1.amzn2023.0.1.noarch          perl-TermReadKey-2.38-9.amzn2023.0.2.x86_64          perl-lib-0.65-477.amzn2023.0.6.x86_64

Complete!
[ec2-user@ip-172-31-10-164 ~]$ git --version
git version 2.40.1
[ec2-user@ip-172-31-10-164 ~]$ cd ~/.ssh/
[ec2-user@ip-172-31-10-164 .ssh]$ ls
authorized_keys
[ec2-user@ip-172-31-10-164 .ssh]$ ssh-keygen -t rsa -C 'jkjk128jkjk@gmail.com'
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ec2-user/.ssh/id_rsa
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:GwCuHzNz93lEyW6eBP3DP4lEBjqpnS3vwApSjeXI+cw jkjk128jkjk@gmail.com
The key's randomart image is:
+---[RSA 3072]----+
|    .      .     |
|   . .    oo..   |
|    . .. +. =o   |
|   .. B.o ++oo   |
|  . =*.+S+ .=.+  |
|   ..*+..+o*...o.|
|   ... E.oo.+. o.|
|    . . . o.    .|
|       .   .     |
+----[SHA256]-----+
[ec2-user@ip-172-31-10-164 .ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC2dPwrA2pK4CSyfBMkcmsB0B4htz6/yQDeBJKHuVOQCKzGhsWiK0vb+039bnPwUUtxL3iGInLtvddFmUbUofLdfNdt9yL1UA4XBc4B+tEUbxgjhfHPrKTZybAJRdtKFkFnVKrOMnONjHZUympWo+AxZlcvfKTkxduc8dBb3z7dw1fpLTvqQ1msPaL5DQL8bXgo7u8F8/K9ICgjrfXNPeVHDgo6KAIKtHEoS41ZyXlYajl1hnC1DO+3qNthWdtBGTsZidbZC1XgFW+eD6AvmVyuH0HDxCoJ4S9m4PlIHSjJJGAbjZYGIp56DP9muAJbaOTgFQfTOPZQkkud+uPASezoKPAYa5zkBeR3IRgIor0fQ3cIL0V/5hLNplOiG27yXzv46S09nTPKajvlBRgqAYGq92MusMENPEH3FPpLd4y4tZHZnOt03SbpNmRHkO/SIZejuk11JY+I7ELlX6J+FwuFTarVfQUtYjy8QInFAzlXEsBYYwwohjr35w553r8pBu8= jkjk128jkjk@gmail.com

github에 접속해서 settings-SSHandGPGkeys에서 키를 등록한다.

이후 git clone을 통해 코드를 가져올 수 있다.