컴퓨터 에 github 와 gitlab 를 동시에 사용 합 니 다.

8467 단어 git.
프로젝트 1: ssh key 가 github 와 gitlab 를 동시에 연결 하 는 솔 루 션 을 강력 히 추천 합 니 다.
gitlab 의 ssh 로 github 연결 하기
https://blog.csdn.net/liyanlei5858/article/details/79108060
 
프로젝트 2: 서로 다른 ssh key 는 github 와 gitlab 를 연결 하고 경로 설정 파일 (config) 이 있 습 니 다.
http://www.arccode.net/config-multi-git-account-and-workspaces.html
Git 을 사용 하여 github 과 gitlab 의 열 쇠 를 만 듭 니 다.
주: windows 명령 행 이 좋 지 않 습 니 다. Windows 친구 로 설치 하 는 것 을 권장 합 니 다 gitbashssh 키 파일 은 운영 체제 의 현재 사용자 디 렉 터 리 .ssh 하위 디 렉 터 리 에 기본적으로 저 장 됩 니 다.
이름 이 붙 은 열 쇠 를 만 들 기 위해 현재 디 렉 터 리 로 전환 .ssh
$ cd ~
$ cd .ssh

github 열쇠 생 성
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/ZL-arccode/.ssh/id_rsa): github_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in github_id_rsa.
Your public key has been saved in github_id_rsa.pub.
The key fingerprint is:
SHA256:MV7M1OCoiiIazgV8D52uNxhs9zi840PbT2CfOFDLhYQ [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|     .. ....     |
|    E. + +.      |
|      + = +      |
| .   = = +       |
|  j.= C S        |
|   +** + .       |
|   +oO= +        |
| .ooOi=o         |
| .o=B* o.        |
+----[SHA256]-----+

자신의 gitlab 키 생 성
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/ZL-arccode/.ssh/id_rsa): gitlab_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in gitlab_id_rsa.
Your public key has been saved in gitlab_id_rsa.pub.
The key fingerprint is:
SHA256:2zfJw2RePrrGc6qKqIvH3qylCmzimIpiUKKAWB87A98 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|ooo +  o+        |
|+. + = o.o .     |
|. . + + E +      |
|   . + + +       |
|    . . S .      |
|o  .   . .       |
|o+. ...          |
|Xoi=  o..        |
|/B=c+ooo         |
+----[SHA256]-----+

회사 gitlab 열쇠 생 성
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/ZL-arccode/.ssh/id_rsa): gitlab_gyenno_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in gitlab_id_rsa.
Your public key has been saved in gitlab_id_rsa.pub.
The key fingerprint is:
SHA256:2zfJw2RePrrGc6qKqIvH3qylCmzimIpiUKKAWB87A98 [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|ooo +  o+        |
|+. + = o.o .     |
|. . + + D +      |
|   . + + +       |
|    . . S .      |
|o  .   . .       |
|o+. ...          |
|Xii=  o..        |
|/B=c+ooo         |
+----[SHA256]-----+

이후 ~/.ssh 디 렉 터 리 에 6 개의 파일 이 추 가 됩 니 다.
  • github_id_rsa
  • github_id_rsa.pub
  • gitlab_id_rsa
  • gitlab_id_rsa.pub
  • gitlab_gyenno_id_rsa
  • gitlab_gyenno_id_rsa.pub

  • github 와 gitlab 웹 페이지 를 열 고 github_id_rsa.pub, gitlab_id_rsa.pub, gitlab_gyenno_id_rsa.pub 각각 대응 하 는 sshkey 에 설정 합 니 다.
    주: 공개 키 (. pub) 를 업로드 하지 않 으 면 연결 시 알림 Permission denied (publickey).config 파일 을 사용자 정의 하여 로 컬 git 가 서로 다른 창고 에 접근 할 때 서로 다른 열 쇠 를 사용 하도록 지도 합 니 다.
    $ cd ~
    $ cd .ssh
    $ vim config
    

    config 내용 은 다음 과 같 습 니 다.
    # github
    Host github
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_id_rsa
    # gitlab(  ) 
    Host gitlab
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab_id_rsa
    # gitlab(  )
    Host gitlab_gyenno
    HostName gitlab.gyenno.com
    User git
    IdentityFile ~/.ssh/gitlab_gyenno_id_rsa
    

    연결 성공 여부 테스트
    $ ssh -T github
    
    Enter passphrase for key 'C:/Users/ZL-arccode/.ssh/github_id_rsa':
    Hi arccode! You've successfully authenticated, but GitHub does not provide shell access.
    
    $ ssh -T gitlab
    Enter passphrase for key '/c/Users/ZL-arccode/.ssh/gitlab_id_rsa':
    Welcome to GitLab, username!
    
    $ ssh -T gitlab_gyenno
    Enter passphrase for key '/c/Users/ZL-arccode/.ssh/gitlab_gyenno_id_rsa':
    Welcome to GitLab, username!
    

    여기 githubgitlab 는 config 에 설 치 된 host 입 니 다.이 host 에 따라 git 에서 설정 에 대응 하 는 주 소 를 찾 을 수 있 습 니 다.
    창 고 를 설정 하여 서로 다른 창고 의 프로젝트 를 다른 디 렉 터 리 에서 작업 하도록 합 니 다.
    필 자 는 다음 과 같이 설정 합 니 다.
  • github 작업 디 렉 터 리:  ~/workspace/github
  • gitlab 작업 디 렉 터 리 (개인):  ~/workspace/gitlab
  • gitlab 작업 목록 (회사):  ~/workspace/gitlab_gyenno

  • 현재 설정 검사git config --list
    github 설정, 제출 할 사용자 이름과 email (전역)
    $ cd ~/workspace/github
    $ git config --global user.name 'arccode'
    $ git config --global user.email '[email protected]'
    

    gitlab 설정 (개인), 제출 할 사용자 이름과 email (부분)
    $ cd ~/workspace/gitlab
    $ git config --local user.name 'username'
    $ git config --local user.email '[email protected]'
    

    gitlab 설정 (회사), 제출 할 사용자 이름과 email (부분)
    $ cd ~/workspace/gitlab_gyenno
    $ git config --local user.name 'username'
    $ git config --local user.email '[email protected]'
    

    창고 에서 클론 프로젝트
    github
    $ git clone git@github:arccode/littlebird-mybatis-generator-core.git
    

    창고 클 라 이언 트 프로젝트 의 명령 은...  git clone [email protected]:arccode/littlebird-mybatis-generator-core.git
    설정 되 어 있 기 때문에 git 를 사용 하면 config 자동 으로 찾 을 수 있 습 니 다[email protected]
    gitlab (개인)
    $ git clone git@gitlab:arccode/arccode.net.git
    

    gitlab (회사)
    $ git clone git@gitlab_gyenno:backend/GyennoMedicalCloud.git
    

    명령 수정 원인 동일
     
    위 절 차 를 마치 고 Git clone 을 실행 하면 아래 의 오 류 를 계속 보고 합 니 다.
    git clone Permission Denied (publickey) 문제 해결
    다음 글 을 참고 하여 집행 해 야 한다.
    단계 3 의 1, 2 명령
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/github_id_rsa
    ssh-add ~/.ssh/gitlab_id_rsa
    원본 주소:https://blog.csdn.net/sxg0205/article/details/81412921
    로 컬 git bash git clone 사용 하기[email protected]: * *. git 방식 으로 github 코드 를 로 컬 로 다운로드 할 때 ssh key 에 의존 해 야 합 니 다. 권한 부족 문제 가 발생 했 을 때 보통 SSH key 가 효력 을 잃 거나 SSH key 가 존재 하지 않 습 니 다. SSH key 를 다시 만 들 면 문 제 를 해결 할 수 있 습 니 다.
    단계 1. 로 컬 ssh key 가 존재 하 는 지 확인 합 니 다.
        1. windows 아래 시작 - 검색 상자 입력 git bash, git bash 창 열기;
        2. git base 창 에 명령 어 입력 ss ~ /. ssh / ssh 키 가 존재 하 는 지 확인 하기;
        3. key 가 존재 하지 않 으 면 절차 2 에 따라 다시 생 성 되 고 ssh key 가 존재 하면 절차 2, 실행 절차 3 을 건 너 뜁 니 다.
    단계 2. ssh key 생 성
        1. 계속 진행 하 는 git bash 창 명령:
                ssh - keygen - t rsa - b 2048 - C "당신 의 메 일 주소"
               메 일 주 소 를 자신의 메 일 주소 로 변경 합 니 다. 이 메 일 주소 의 앞 뒤 에 있 는 작은 따옴표 가 영문 형식 작은 따옴표 입 니 다.
        2. 명령 실행 후 페이지 알림:
               
               Generating public/private rsa key pair.            Enter file in which to save the key (/c/Users/***/.ssh/id_rsa):
             ***현재 로그 인 사용자 이름 을 표시 합 니 다. 수정 하지 않 고 바로 돌아 오 면 생 성 된 rsa 파일 을 기본 이름 으로 저장 합 니 다.
             다시 돌아 오 는 알림:
             Enter passphrase (empty for no passphrase):           Enter same passphrase again:           Github 에 코드 를 제출 / l 로 끌 어 올 릴 때 필요 한 비밀번호 와 비밀번호 확인 을 알려 줍 니 다.
             비밀 번 호 를 설정 한 후 다시 차 로 돌아 가 귀하 의 identification has been saved in... 즉, ssh key 생 성 성공 을 표시 합 니 다.
    단계 3. sshkey 를 ssh - agent 에 추가 합 니 다.
        1. eval "$(ssh - agent - s)" 를 실행 하여 ssh - agent 가 열 린 상태 인지 확인 하고 pid 를 인쇄 합 니 다. 사용 중 임 을 표시 합 니 다.
        2, 실행 명령 ssh - add ~ /. ssh / idrsa 는 ssh key 를 ssh 에이전트 에 추가 합 니 다. 이 단 계 는 단계 2 설정 의 암 호 를 입력 하 라 고 요구 합 니 다.
              주의해 야 할 것 은 오류 가 발생 할 수 있 습 니 다: Could not open a connection to your authentication agent, 나의 해결 방법 은 현재 git 를 끄 는 것 입 니 다.                  bash 창, git bash 를 관리자 로 다시 실행 하면 문 제 를 해결 합 니 다.
    단계 4. ssh key 를 guthub 에 추가 합 니 다.
         1. 로그 인https://github.com/페이지 오른쪽 상단 에 자신의 얼굴 오른쪽 화살표 에서 우 클릭 하고 탄 상자 에서 setting 기능 에 들 어 갑 니 다.
                
         2 、 화면 오른쪽 메뉴 에서 SSH 와 GPG 키 를 선택 하고 새 SSH 키 를 선택,
        
    저장 하면 됩 니 다.
    STEP 5: git clone 다운로드 코드
       절차 가 끝 났 습 니 다. 이 때 로 컬 에서 git clone 방식 으로 코드 를 다운로드 하면 됩 니 다. 

    좋은 웹페이지 즐겨찾기