티스토리 뷰
Are you facing plenty of fatal errors resulted from adding a ssh key for multiple accounts from the same computer in GitHub?
As GitHub technically doesn't allow the same generated ssh key for more than two accounts unlike GitLab or other competitive platforms, there is only way to solve the problem is to generate a new ssh key for your second account. Please kindly be noted that I had registered my ssh key (from the default file named - id_rsa) into my company account, but strongly wanted to do my toy project with my personal github account in the same desktop. The guidelines below are based in MacOS and zsh shellscript.
- STEP 1) Generate another ssh key file.
ssh-keygen -t rsa -b 4096 -C "your github email address"
# ex) ssh-keygen -t rsa -b 4096 -C "example@gmail.com"
# -t : key type
# -b : how many bits to be gnerated
# -C : comment
*** It would be distinguishable if you name your pub file name by refering to related info.
- STEP 2) Add a newly-generated ssh key to ssh-agent.
ssh-add ~/.ssh/(key file name)
# ex) ssh-add ~/.ssh/id_rsa_example
***Check if all keys specified in config have been added with the command "ssh-add -l"
- STEP 3) Copy a generated key and add a new ssh key in settings of your github account.
cat ~/.ssh/id_rsa.pub | pbcopy
- Copy the generated ssh key.
- Add it to your account settings.
- STEP 4) Repeat the steps to add new hash keys for another or other accounts. Make sure that filename is not the identical to the existing one.
- STEP 5) Configure generated ssh keys in local.
cd ~/.ssh
vim config
## Generate it with the cli "touch ~/.ssh/config" if you don't have it yet.
***🤫 You DO NOT have to remove or modify other configurations. Just add as many as keys you generated for accounts.
Host xxx.xx.xx.xx
HostName xxx.xx.xx.xx
User grusha
# for first account
# after "dash" you should write a username of an account.
Host github.com-grusha
HostName github.com
User git
UseKeyChain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_grusha
IdentitiesOnly yes
# for second account
Host github.com-grushenka
HostName github.com
User git
UseKeyChain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_grushenka
IdentitiesOnly yes
- STEP 6) Add it to authorized_keys in ssh directory.
vim authorized_keys
- STEP 7) Check your remote origin url and configure it to allow to use for a specific account. (IN LOCAL REPOSITORY)
git remote add origin "your git url"
## example -> git remote add origin git@github.com:grusha/repo.git
git remote -v
## example output -> origin git@github.com:example/exampe-app.git (fetch)
## example output -> origin git@github.com:example/exampe-app.git (push)
*Check your remote url and you should config it if there is no specified username between "github.com" and ":useraccount".
open .git/config
*Specify the same username that you specified in ssh config. ex1) git@github.com-grusha:github_id/repository_name.git ex2)git@github.com-grusha:appfirstcourse/app-first-project.git
🔑 If you still encouter errors, try to add user and credential info below.
git config --global user.name "github_id"
git config --global user.email "github_email"
git config confidential.username "github_id"
git config confidential.email "github_email"
- STEP 8) Git push and check it works.
- STEP 9) Try it for another repository from another account and check if second or further key has been successfully added in your github account.
🤷🏼♀️ To sum up, things seem easy and uncomplicated, but you would probably encounter unexpected fiddles that you may be able to handle with this post.
- Total
- Today
- Yesterday
- Laravel
- querydslQclass
- android_app_links_domain
- android_app_link_domain_works_with_adb_but_not_works_with_browser
- flutter
- dagger-hilt
- querydslKotlinError
- Kotlin
- querydsl5.0.0jakarta
- laravel9
- retrofit_generator_conflicts_with_freezed
- RunAFlutterProjectIniPhoneFromVSCode
- Android
- MultipleFirebaseEnvironments
- WirelessDebug
- FirebaseConfigurationForMultipleBuildTypes
- unsplashAPI
- phplaravel
- retrofit_generator
- FlutterWirelessDebuginAOS
- android_app_links
- KotlinFlow
- flutter_storage_not_working_for_the_first_time
- retrofit_toJson()_error
- android_domain
- futter_api
- flutter_secure_storage_issue_iOS
- mvvm
- flutter_android_app_links
- AndroidWirelessDebug
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |