[Env] Git Multi Account 설정

EllaDev·2023년 4월 14일
0

환경설정

목록 보기
2/2

1. ssh 설정

1-1. ssh-keygen 생성

	# .ssh로 이동
	cd ~/.ssh
    
	# ssh-keygen 생성
    # 1>
	ssh-keygen -t rsa -b 4096 -C "userA@gmail.com"
    Generating public/private rsa key pair.
    
    # 2>
    ssh-keygen -t rsa -C "userA@my_email.com" -f "id_rsa_userA"
    
    # key 이름 설정
    Enter file in which to save the key (/Users/ella/.ssh/id_rsa): id_rsa_userA
    
    # 보안을 위해서 설정해야하지만...하지 않음
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in id_rsa_store
    Your public key has been saved in id_rsa_store.pub
    The key fingerprint is:
    SHA256:00000000000000~~~~~~~userA@gmail.com
    The key's randomart image is:
    +---[RSA 4096]----+
    |. o     .        |
    | = ..  o .       |
    |  BE+ = .        |
    | *.* O + .       |
    |ooO B * S        |
    |+*o@ = . .       |
    |=o*.o +          |
    |oo  .. .         |
    |  .. ..          |
    +----[SHA256]-----+
    
    # 확인
    > .ssh  ls   
      id_rsa_userA     
      id_rsa_userA.pub 
      id_rsa_userB       
      id_rsa_userB.pub
    

1-2. ssh 키 등록

# ssh키 등록
  ssh-add id_rsa_userA

1-3. ssh key daemon 추가 및 권한 확인

# ssh key daemon 추가
  $ eval "$(ssh-agent -s)" &&\
   ssh-add -K id_rsa_userA 
   
# 권한 확인
  ssh-add -l

1-3. ssh config 작성하기


# 개인용 계정
  Host userA
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_userA

# 회사용 계정
  Host userB
     HostName github.com
     User git
     IdentityFile ~/.ssh/id_rsa_userB


2. git 설정

2-1. .gitconfig global 설정

# mac에서 git global 설정 수정
  git config --global --edit

# git global setting
  [includeIf "gitdir:~/DEV/GIT-Store"]
   path = DEV/GIT-Store.gitconfig
  [includeIf "gitdir:~/DEV/GIT-Project"]
   path = DEV/GIT-Project/.gitconfig
 
# GIT-Store폴더로 .gitconfig 파일 생성
  cd ~/DEV/GIT-Store
  vi .gitconfig
  
# git local setting
  [user]
        name = "[git name / ex> EllaDev]"
        email = "[git email]"
  [github]
        user = "[git nickname / ex> ella-front-dev]"
 

2-2. 원격 git ssh 설정

  1. ssh public key 복사
# 복사 방법 1>
  cat id_rsa_userA.pub | pbcopy

# 복사 방법 2>
  pbcoby < id_rsa_userA.pub
  1. github에 접속
  2. 접속 후 settings > SSH and GPG keys로 이동
  3. New SSH Key 설정


3. 테스트

ssh daemon 테스트

# ssh -T git@{Host}로 테스트
> ssh -T git@userA

각 계정의 git clone 가능한지 확인

# userA 계정 저장소 clone
> git@userA:userA/repository.git

# userB 계정 저장소 clone
> git@userB:userB/repository.git

Ref>

한 컴퓨터에서 여러 개의 깃허브 계정 사용하기
머신 한 대에서 GIT 계정 여러개 사용하기

profile
Frontend Developer

0개의 댓글