본문 바로가기

Study/GitHub

GitHub | 여러계정 이용하기

1. ssh key 생성

홈 경로에서 .ssh 디렉토리 생성 및 이동

ssh-keygen -t rsa -C [github 이메일 계정] -f [생성될 key 파일명]

형식으로 계정 별 키를 생성

2. config 파일 생성

.ssh 디렉토리 위치에서 config.txt파일 생성

# 개인 계정
Host github.com-[계정1]
	HostName github.com
	User [계정1 이메일]
	IdentityFile ~/.ssh/[계정1 key 파일명]

# 회사 계정
Host github.com-[계정2]
	HostName github.com
	User [계정2 이메일]
	IdentityFile ~/.ssh/[계정2 key 파일명]

위 텍스트처럼 입력 후 저장

3. ssh agent 등록

ssh-add -K ~/.ssh/[계정별 key 파일]
# 혹은
ssh-add [계정별 key 파일]
Identity added: [계정별 key 파일] (git1@email.com)

Identity added: [계정별 key 파일] ([계정별 email]) 코드가 뜨면 완료

Could not open a connection to your authentication agent라는 에러가 발생한다면 아래 명령어를 입력해준후 위의 명령어(ssh-add ~)를 다시 입력

eval "$(ssh-agent -s)"
ssh-add -l

위 명령어를 통해 agent 저장 및 agent목록 확인

4. pub key 등록

github에서 profile setting으로 이동
SSH and GPG keys 메뉴에서 new ssh key클릭
각 계정에 해당하는 public key를 계정 별로 등록

5. 연결 확인

git clone [remote git 주소]

clone하고 init, test 파일 작성하여 commit

push 할 때, 443 에러 발생

git remote set-url origin https://[YOURUSERNAME]@github.com/USERNAME/REPOSITORY.git]

위 명령어 입력 후 push, 해당 계정의 github에 잘 올라왔는지 확인

 


참고

'Study > GitHub' 카테고리의 다른 글

GitHub | 원격저장소와 동기화  (0) 2022.03.27
Git | reset, branch, merge, stash  (0) 2022.03.07
Git | add, commit, log & diff  (2) 2022.03.05
Git | init  (0) 2022.03.04
GitHub 블로그 만들기  (0) 2022.03.03