두 개의 Github계정(개인용, 회사용)을 나눠서 이용하는 방법
터미널을 사용해서 .ssh 로 들어가서 키를 등록해야 한다.
// 1. ssh 진입
$ cd ~/.ssh
// 2. 개인 계정 등록
$ ssh-keygen -t rsa -C “ohmy0418@blahblah.com" -f "id_rsa_personal”
// 위 작성 후 엔터를 치면 아래와 같은 내용이 나옴.
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dpudpu/.ssh/id_rsa_personal): id_rsa_personal
// 3. 회사 계정 등록
$ ssh-keygen -t rsa -C "ohmy0418@blahblah.com" -f "id_rsa_work”
// 위 작성 후 엔터를 치면 아래와 같은 내용이 나옴.
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dpudpu/.ssh/id_rsa): id_rsa_work
위와 같이 등록을 하면 ~/.ssh 경로에 총 4개의 파일이 생성되는 것을 확인할 수 있다.
id_rsa_company.pub
id_rsa_company
id_rsa_personal.pub
id_rsa_personal
$ ssh-add id_rsa_personal
$ ssh-add id_rsa_work
// 키 값 검색하는 방법
cat ~/.ssh/id_rsa_work.pub
cat ~/.ssh/id_rsa_personal.pub
// 2. 키 값 복사하는 방법
pbcopy < ~/.ssh/id_rsa_personal.pub
// CASE 1. ssh 들어가서 config 열기
cd ~/.ssh
open .
// CASE 2-1. config가 없다면 config 생성
touch ~/.ssh/config
// CASE 2-2. config 수정
sudo nano ~/.ssh/config
// config 예
# work
Host work-github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
# personal
Host personal-github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
// 터미널에 아래와 같이 입력
$ ssh -T work-github.com
// 아래와 같은 출력 결과가 나오면 정상적으로 등록 및 설정이 끝남!
Hi ohmy04180! You've successfully authenticated, but GitHub does not provide shell access.
// 터미널에 아래와 같이 입력
$ ssh -T personal-github.com
// 아래와 같은 출력 결과가 나오면 정상적으로 등록 및 설정이 끝남!
Hi gnuoy-oh! You've successfully authenticated, but GitHub does not provide shell access.$ ssh -T company-github.com
// 터미널에서 git config 수정 명령어 입력
vi .gitconfig
// edit
e
// e 편집 키 누르면 아래와 같은 설정 값들이 나옴
// Default
[user]
email = ohmy0418@blahblah.com
name = ohmy04180
[includeIf "gitdir:~/Develop/company/"]
path = ~/.gitconfig-company
// includeIf는 ~/Develop/company/ 디렉터리 아래 있다면
~/.gitconfig-compnay 파일을 불러옵니다.
// ~/.gitconfig-company 파일은 다음과 같습니다.
[user]
email = dpudpu@naver.com
name = dpudpu
git config --list 를 입력하면 아래와 같이 git config 정보를 볼 수 있다.
깃허브에서 클론을 받을 때는 SSH를 이용해서 클론을 하면 된다.
git clone personal-github.com:personal/Study-Git.git
Command + shift + .
[includeIf “girdir: ~/B-IRIS-Design-System”]