728x90
반응형
현재 상황
이미 회사 github 계정 ssh 연동 및 config 설정이 되어있는 상태
이 상태에서, 개인 github 계정을 연동하고 싶었다.
복잡스러웠으니, 기록.
1. 개인 Github 계정 ssh-key 생성 및 등록
// ssh-keygen -t rsa -b 4096 -C [이메일]
$ ssh-keygen -t rsa -b 4096 -C "test@gmail.com"
Enter file in which to save the key (/Users/baechu/.ssh/id_rsa): key 이름
key 이름을 입력하라고 뜨는데,
나는 기존 회사계정 ssh 발급시 기본이름인 id_rsa 로 발급받았으므로, 이번엔 다른이름으로 설정해주었다.
여기까지하면, ~/.ssh 경로에 총 4개의 파일이 생성되고, 생성된 키를 ssh-add 로 등록한다.
id_rsa.pub
id_rsa
key_이름.pub
key_이름
$ ssh-add key_이름
$ ssh-add id-rsa
그리고, 발급받은 개인용 ssh 를 github와 연동합니다.
cat key.pub -> 복사
github - settings - SSH and GPG keys - New SSH Key
2. ~/.ssh/config 파일 설정
# 회사
Host github.com-회사이름
HostName github.com
User 회사github 계정
IdentityFile ~/.ssh/id_rsa
# 개인용
Host github.com-baechu
HostName github.com
User 개인용 github 계정
IdentityFile ~/.ssh/key_이름
그리고 ssh -T 명령어로 잘 연동되었는지 확인.
$ ssh -T github.com-회사이름
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T github.com-baechu
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.
3. ~/.gitconfig
vi ~/.gitconfig 열어서 설정을 또 해주자.
[user]
email = 회사계정
name = 회사계정이름
[includeIf "gitdir:~/개인용계정으로_작업할_디렉토리/"]
path = .gitconfig-baechu
# ~/.gitconfig-baechu
[user]
email = 개인용계정
name = 개인용이름
~/개인용계정으로_작업할_디렉토리/ 에서는 개인용계정 으로 commit/push 가 가능합니다.
4. 이후
# 신규 프로젝트 클론
$ git clone git@HOST:DIRECTORY/TEST.git
# 기존 프로젝트
$ git remote set-url origin git@HOST:DIRECTORY/TEST.git
728x90
반응형
'🗂️git' 카테고리의 다른 글
[Git] 자주쓰는 command (0) | 2020.11.29 |
---|---|
[Git / Git Hub] Git 용어 재 정리 (0) | 2020.06.23 |
[Git / Git Hub] Branch (0) | 2020.06.21 |
[Git / Git Hub] Git 혼자 하기 편 (0) | 2020.06.21 |
[Git / Git Hub] Git의 기본 (0) | 2020.06.21 |