[GitHub] 여러 계정에서 ssh로 git clone 하기

ASHAPPYASIKNOW·2022년 8월 20일
0

GIT/GITHUB

목록 보기
1/3
post-thumbnail

Quick Guid

Process

1) ssh key 생성
2) github에 key 등록
3) config에 Host에 -username 을 추가해 줌
4) git clone 시에도 git@github.com-username:username ... 추가

1) SSH Key 생성

> cd ~/.ssh
> ssh-keygen -t ed25519 -C "ashappyasitis@gmail.com" -f "id_ed25519_github_ashappy"
> ssh-keygen -t ed25519 -C "kevin-jang@gmail.com" -f "id_ed25519_github_kevin"

2) SSH Publick Key 등록

https://github.com/settings/keys

3) config 파일

폴더 이동 및 파일 만들기

> cd ~/.ssh
> vim config

config 파일 내용

Host github.com-ashappyasitis
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519_github_ashappy
Host github.com-kevin-jang
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519_github_kevin

4) git clone 실행

> cd ~/workspace
> git@github.com-ashappyasitis:ashappyasitis/mysql-deadlock-example.git
> git@github.com-kevin-jang:kevin-jang/my-example.git

상세 설명

0) 계정 설명

1번 계정

username: ashappyasitis
clone 명령어: git clone git@github.com:ashappyasitis/mysql-deadlock-example.git

2번 계정

username: kevin-jang
clone 명령어: git clone git@github.com:kevin-jang/my-example.git

Username 확인방법1

Username 확인방법 2

GitHub 무료 버전을 사용하고 있는 경우


1) SSH Key 생성

> cd ~/.ssh
> ssh-keygen -t ed25519 -C "ashappyasitis@gmail.com" -f "id_ed25519_github_ashappy"
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ed25519_github_ashappy
Your public key has been saved in id_ed25519_github_ashappy.pub
The key fingerprint is:
SHA256:C/zyoDey2Xo0YF+ZAfLm7kGzmeQYNDNooq+rL17Lml8 ashappyasitis@gmail.com
The key's randomart image is:
+--[ED25519 256]--+
|    . ..         |
|   . o  .        |
|. o = o  +       |
|.o .oB  +        |
|.  ..oB.S        |
| .   B+B .       |
|  ...EX.o        |
|..+ +=+=         |
|*B++=*o..        |
+----[SHA256]-----+
> ssh-keygen -t ed25519 -C "kevin-jang@gmail.com" -f "id_ed25519_github_kevin"
Generating public/private ed25519 key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_ed25519_github_kevin
Your public key has been saved in id_ed25519_github_kevin.pub
The key fingerprint is:
SHA256:RkwE0sEMGhqIYUE4exkzmWVAEm/2141wJMu/HaDUtL4 kevin-jang@gmail.com
The key's randomart image is:
+--[ED25519 256]--+
|XB====++=        |
|*=*+ o+O .       |
|.o==  = B        |
|.oo. . O +       |
| .  . o S o      |
|     . . + .     |
|        E .      |
|                 |
|                 |
+----[SHA256]-----+

2) SSH Publick Key 등록

https://github.com/settings/keys

Public Key 복사

> $ cat id_ed25519_github_ashappy.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEmYywcnjmM8IBtx+hE+zLNkS+A/EXyEhWDa93xkO4TC ashappyasitis@gmail.com

Settings/SSH and GPG keys/New SSH key





ashappyasitis 계정에 SSH Public key 를 등록했던 것 처럼 kevin-jang 계정에도 같은 방식으로 SSH Public key 를 등록하면 된다. 여기서는 설명을 생략 한다.

3) config 파일

폴더 이동 및 파일 만들기

> cd ~/.ssh
> vim config

config 파일 내용

private-key를 연결 하면 된다.

Host github.com-ashappyasitis
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519_github_ashappy
Host github.com-kevin-jang
        HostName github.com
        User git
        Port 22
        IdentityFile ~/.ssh/id_ed25519_github_kevin

4) git clone 실행

git@github.com에 -username 을 추가해 주면 된다.

FROM: git@github.com:username/repository
TO: git@github.com-username:username/repository

FROM: git@github.com:ashappyasitis/mysql-deadlock-example.git
TO: git@github.com-ashappyasitis:ashappyasitis/mysql-deadlock-example.git

동작 확인

> git clone git@github.com-ashappyasitis:ashappyasitis/mysql-deadlock-example.git
The authenticity of host 'github.com (20.200.245.247)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
bash: $: command not found
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 47 (delta 3), reused 47 (delta 3), pack-reused 0
Receiving objects: 100% (47/47), 65.06 KiB | 362.00 KiB/s, done.
Resolving deltas: 100% (3/3), done.

git clone git@github.com-kevin-jang:kevin-jang/my-example.git 동작 확인은 생략


REFERENCES

Generating a new SSH key and adding it to the ssh-agent

profile
36.9 It's good time to start something new

0개의 댓글