A comprehensive guide to configuring multiple Git accounts using SSH keys
Gitμ μ¬μ©νλ€ λ³΄λ©΄ μ¬λ¬ κ³μ μΌλ‘ μμ ν΄μΌ ν λκ° μμ΅λλ€. μλ₯Ό λ€μ΄, κ°μΈ νλ‘μ νΈλ κ°μΈ GitHub κ³μ μΌλ‘ κ΄λ¦¬νκ³ , νμ¬ νλ‘μ νΈλ νμ¬ κ³μ μΌλ‘ κ΄λ¦¬ν΄μΌ νλ μν©μ΄ μμ μ μμ΅λλ€. μ΄λ΄ λ μ¬λ¬ κ³μ μ ν¨μ¨μ μΌλ‘ κ΄λ¦¬ν μ μλ λ°©λ²μ΄ νμν©λλ€. SSHλ₯Ό μ¬μ©νλ©΄ λ³λμ λΌμ΄λΈλ¬λ¦¬ μ€μΉ μμ΄ λ‘컬 νκ²½μμ μ¬λ¬ κ³μ μ μμ½κ² κ΄λ¦¬ν μ μμ΅λλ€.
ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/github_user1_ed25519
ssh-keygen -t ed25519 -C "your_other_email@example.com" -f ~/.ssh/github_user2_ed25519μ λͺ λ Ήμ΄λ₯Ό μ€ννλ©΄ ~/.ssh/ λλ ν 리μ κ°κ° github_user1_ed25519μ github_user2_ed25519λΌλ μ΄λ¦μ SSH ν€ μ(κ³΅κ° ν€μ κ°μΈ ν€)μ΄ μμ±λ©λλ€.
Host github-user1
HostName github.com
User git
IdentityFile ~/.ssh/github_user1_ed25519
Host github-user2
HostName github.com
User git
IdentityFile ~/.ssh/github_user2_ed25519μμ κ°μ΄ μ€μ νλ©΄ github-user1κ³Ό github-user2λΌλ νΈμ€νΈλͺ μ΄ κ°κ°μ SSH ν€μ μ°κ²°λ©λλ€.
User gitμ΄ μ€μ λμ΄ μμΌλ―λ‘ git@ μ λμ¬λ μλ΅ν΄λ λκ³ λΆμ¬λ λ©λλ€.git clone github-user1:user1/test.git
github-user2 κ³μ μ μ¬μ©ν κ²½μ°μλ λ€μκ³Ό κ°μ΄ μ
λ ₯ν©λλ€.git clone github-user2:user2/test.gitμ΄ λ°©μμΌλ‘ μ¬λ¬ κ³μ μ μ¬μ©ν μ μμΌλ©°, Gitμ΄ κ° κ³μ μ λ§λ SSH ν€λ₯Ό μλμΌλ‘ μ ννκ² λ©λλ€.
chmod 600 ~/.ssh/github_user1_ed25519
chmod 600 ~/.ssh/github_user2_ed25519μ΄μ λͺ¨λ μ€μ μ΄ μλ£λμμ΅λλ€. λ‘컬 νκ²½μμ μ¬λ¬ Git κ³μ μ κ΄λ¦¬ν λ, κ° κ³μ λ§λ€ λ€λ₯Έ SSH ν€λ₯Ό μ¬μ©νμ¬ μμ νκ² μμ μ μ§νν μ μμ΅λλ€ ~