Code개발일지
[Git] ssh-key 여러개 사용
Minhhk
2024. 12. 8. 12:44
깃허브 두개의 아이디로 사용해야 할 일이 생겨서 config 에 등록해서 사용
💡 ssh key 생성,, 적용 이메일 및 ssh key 이름 지정
ssh-keygen -t rsa -b 4096 -C "test@gmai.com" -f ~/.ssh/id_rsa_B
~/.ssh/id_rsa_B.pub >> github 에서 ssh-key 등록 이후
# Create the config file with Powershell
New-Item -Path $HOME\\.ssh\\config -ItemType File
# Open config File with Notepad
C:\\WINDOWS\\System32\\notepad.exe $HOME\\.ssh\\config
# or Open file with Visual Code
code $HOME\\.ssh\\config
# or Open file with Visual Code
code $HOME\\.ssh\\config
→
💡 config 파일
# A 아이디의 설정
Host github.com-A
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_A
# B 아이디의 설정
Host github.com-B
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_B
→ 사용
git init
git branch -M main
git remote add origin git@github.com-B:사용자명/레포지토리명.git
(이전 연결 있을 시)
git remote -v
git remote remove origin