GitLab에 SSH 연결 설정
소개
GitLab.com을 업무로 사용하게 되었습니다만 보안 대책을 위해 2단계 인증 설정을 했는데, Eclipse나 커멘드 라인으로부터 https 접속할 수 없게 되었기 때문에(당연히), 처음으로 SSH 접속에 도전했습니다.
개인 액세스 토큰을 생성하고 이를 비밀번호로 설정하여 https 연결이 가능한 것 같습니다.
필요한 분은 이 페이지 를 참고해 주십시오.
 PC 환경
SSH 키 생성
Git Bash를 시작하고 ssh-keygen 명령을 실행합니다.
옵션
내용
-t
키 타입
-b
키 길이(비트)
-C
코멘트(메아드가 통례인 것 같다)
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
저장 위치가 표시되므로 문제가 없으면 그대로 Enter 키를 누릅니다.Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxxxxxx/.ssh/id_rsa):
비밀번호를 설정합니다.
설정하면 비공개 키 자체도 암호화되지만, fetch 등 원격 리포지토리에 액세스할 때마다 패스프레이즈를 요구됩니다.
여기서는 지정하지 않고 그대로 Enter 키를 누릅니다.Created directory '/c/Users/xxxxxxxx/.ssh'.
Enter passphrase (empty for no passphrase):
다시 Enter 키를 누릅니다.Enter same passphrase again:
SSH 키 생성이 완료되었습니다.Your identification has been saved in /c/Users/xxxxxxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxxxxxx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:VJ2U...  xxxxxxxx@pcname
The key's randomart image is:
+---[RSA 4096]----+
|   **E=+=+o+.+..+|
|  o.=.=+.B= = ..o|
| . . + .B..o o ..|
|  . .  .o.  o . o|
|   . .  S  . o  o|
|    .     + o   .|
|         o =     |
|          o      |
|                 |
+----[SHA256]-----+
종류
파일 경로
비밀키
C:\Users\xxxxxxxx\.ssh\id_rsa
공개키
C:\Users\xxxxxxxx\.ssh\id_rsa.pub
 공개 키 복사$ clip < ~/.ssh/id_rsa.pub
공개 키의 내용이 클립보드에 복사됩니다.
(macOS의 경우 pbcopy 명령이라고합니다)
 GitLab에 공개 키 등록
GitLab에 로그인하고 오른쪽 상단에서 설정을 선택합니다.
 
왼쪽 메뉴에서 [SSH 키]를 선택하고 키 열에 방금 복사한 공개 키를 붙여넣습니다.
제목에 알기 쉬운 모든 이름을 입력합니다.
키 추가 버튼을 클릭하면 완료됩니다.
 
 설정 확인
 Git Bash에서 ssh 명령 실행
Git Bash를 시작하고 ssh 명령을 실행합니다.$ ssh -T [email protected]
처음만 아래와 같이 표시되므로 yes를 입력합니다.The authenticity of host 'gitlab.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:HbW3.........
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,35.231.145.151' (ECDSA) to the list of known hosts.
아래와 같이 마지막 행에 표시되면 OK.Welcome to GitLab, @xxxxxxxx!
공개키가 GitLab 측에 등록되어 있지 않은 경우는 다음과 같이 표시됩니다.[email protected]: Permission denied (publickey).
이상입니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(GitLab에 SSH 연결 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/gate9/items/2ae95dc68cd02cb901d0
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/xxxxxxxx/.ssh/id_rsa):
Created directory '/c/Users/xxxxxxxx/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/xxxxxxxx/.ssh/id_rsa.
Your public key has been saved in /c/Users/xxxxxxxx/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:VJ2U...  xxxxxxxx@pcname
The key's randomart image is:
+---[RSA 4096]----+
|   **E=+=+o+.+..+|
|  o.=.=+.B= = ..o|
| . . + .B..o o ..|
|  . .  .o.  o . o|
|   . .  S  . o  o|
|    .     + o   .|
|         o =     |
|          o      |
|                 |
+----[SHA256]-----+
$ clip < ~/.ssh/id_rsa.pub
공개 키의 내용이 클립보드에 복사됩니다.(macOS의 경우 pbcopy 명령이라고합니다)
GitLab에 공개 키 등록
GitLab에 로그인하고 오른쪽 상단에서 설정을 선택합니다.
 
왼쪽 메뉴에서 [SSH 키]를 선택하고 키 열에 방금 복사한 공개 키를 붙여넣습니다.
제목에 알기 쉬운 모든 이름을 입력합니다.
키 추가 버튼을 클릭하면 완료됩니다.
 
 설정 확인
 Git Bash에서 ssh 명령 실행
Git Bash를 시작하고 ssh 명령을 실행합니다.$ ssh -T [email protected]
처음만 아래와 같이 표시되므로 yes를 입력합니다.The authenticity of host 'gitlab.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:HbW3.........
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,35.231.145.151' (ECDSA) to the list of known hosts.
아래와 같이 마지막 행에 표시되면 OK.Welcome to GitLab, @xxxxxxxx!
공개키가 GitLab 측에 등록되어 있지 않은 경우는 다음과 같이 표시됩니다.[email protected]: Permission denied (publickey).
이상입니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(GitLab에 SSH 연결 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/gate9/items/2ae95dc68cd02cb901d0
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
Git Bash에서 ssh 명령 실행
Git Bash를 시작하고 ssh 명령을 실행합니다.
$ ssh -T [email protected]
처음만 아래와 같이 표시되므로 yes를 입력합니다.The authenticity of host 'gitlab.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:HbW3.........
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,35.231.145.151' (ECDSA) to the list of known hosts.
아래와 같이 마지막 행에 표시되면 OK.Welcome to GitLab, @xxxxxxxx!
공개키가 GitLab 측에 등록되어 있지 않은 경우는 다음과 같이 표시됩니다.[email protected]: Permission denied (publickey).
이상입니다.
                Reference
이 문제에 관하여(GitLab에 SSH 연결 설정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/gate9/items/2ae95dc68cd02cb901d0텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)