So, I have my work computer and that is connected to my GitHub Enterprise Account (github.company.com) on the terminal. Now I want to set up my personal account (github.com) on here too.
I've been following this tutorial - https://code.tutsplus.com/tutorials/quick-tip-how-to-work-with-github-and-multiple-accounts--net-22574
and on step 3 when I have to create my config file should my HostName be github.company.com or github.com? Can I have any (meaningful) name for Host? Also, what does User here mean?
Also, how do I switch between both these accounts on the terminal - i.e. my personal and my enterprise account? There are certain things I need to commit from my personal account, and use the enterprise account with the rest.
Detailed steps to use two GitHub accounts on the same PC as below:
1. Create SSH key for the github.company.com account
If you already added the SSH key to your github.company.com account, then skip this step.
First, use ssh-keygen to create id_rsa and id_rsa.pub in C:\Users\username\.ssh.
Then, add the content of id_rsa.pub file as a SSH key in github.company.com account.
2. Create SSH Key for your personal account github.com
Use ssh-keygen -t rsa -C "email address for the personal github account", and save the key in /c/Users/username/.ssh/id_rsa_personal.
Now add the content of id_rsa_personal.pub file as a SSH Key in your personal GitHub account.
3. Config the two SSH Keys
In C:\Users\username\.ssh diectory, create a config file with below content:
Host github.company.com
HostName github.company.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
4. Work with the two GitHub accounts by SSH protocol
You can clone your github.company.com account by:
git clone git#github.company.com:companyaccountname/reponame
And then add the personal account as a remote in the local repo by:
git remote add personal git#github-personal:personalaccountname/reponame
To get the file from personal account to company repo by below commands:
git merge upstream master --allow-unrelated-histories
# make changes
git add .
git commit -m 'add the changes from peronal repo'
git push origin master
To commit/push changes from local company repo by the committer of the personal repo, you just need to re-config the username and email before committing changes in the local repo:
git config user.name <personal github account username>
git config user.email <email for login the personal github account>
When you want to commit changes with the company account, just re-config username and email again before committing changes.
Related
When I try to push my files to the git server I faced this problem.
`~ git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
So, I've entered git push --set-upstream origin main in the terminal. It was showing up the following error.
ERROR: Permission to adivenkat05/C-Assignments.git denied to deploy key
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
So, after searching for the solution, it was that we need to upload our ssh key in the git server (Deploy Key).
I've uploaded that same key to another repository but it ended up showing me this "So, after searching for the solution, it was that we need to upload our ssh key in the git server (Deploy Key).
I've uploaded that same key to another repository but it ended up showing me this "Key is already in use".
So, it's not possible to have multiple ssh keys in a particular machine, right?
How do I tackle this problem?".
The second error is different, and refer to an authentication problem.
You can have multiple keys, a deploy one and one associated with your user account.
Create a new dedicated key, and add it to your account:
ssh-keygen -t rsa -P "" -f ~/.ssh/me
Reference it in a ~/.ssh/config file:
Host gh
Hostname github.com
User git
IdentityFile ~/.ssh/me
IdentitiesOnly yes
And your SSH URL becomes gh:me/myRepository. (no more git#github.com:...)
You can test your SSH key with ssh -Tv gh.
It it works:
cd /path/to/my/local/repo
git remote set-url origin gh:adivenkat05/C-Assignments.git
git push -u origin main
i am trying to configure my git to deploy my hexo blog on github.
Firstly,I
git config --global user.name "my github username"
git config --global user.email "my github registration email"
Then,I use ssh-keygen -t rsa -C 'my github registration email to generate ssh key and add it to my github authentication keys.
But when I type command ssh -T git#github.com,the git bash shows:
RSA key fingerprint is SHA256:rEmlJenVMSL5GVemS*********************.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
git#github.com's password:
I tried input my github password,but it shows Permission denied, please try again.immediately.
After trying three times,it shows git#github.com: Permission denied (publickey,password,keyboard-interactive).
My OS is windows 10.
How can i slove this?
First, the user.name/email setting has nothing to do with how GitHub authenticate you. It only matters for local commit authorship.
Second, the missing step in your process is the copy of the ~/.ssh/id_rsa.pub (the public key) to your GitHub settings SSH page.
That will allow GitHub to identify you as your GitHub account. See "Adding a new SSH key to your GitHub account".
I have a question regarding managing two Github accounts in my machine (office and personal). Whenever I create a repo in personal am I supposed to create a new ssh key(As my office git account username and email are global)? Using windows credentials way I'm prompted to enter the username and password for the first time I do remote push then onwards I need not have to do that for that particular repo. I wanted to try by ssh(to avoid entering my git account credentials for the first time) or can I stick with the windows credential manager way?
Whenever I create a repo in personal am I supposed to create a new ssh key(As my office git account username and email are global)?
No: the SSH key remains the same and is used to authenticate you to your personal GitHub account.
You only need to register that key in your ~/.ssh/config file:
Host perso
Hostname github.com
User git
IdentityFile ~/.ssh/myPersoKey
Then, in your local cloned repository:
cd /path/to/local/clone
git remote set-url origin perso:<me>/<myrepo>
Then a git push will use the SSH URL, with the right perso key.
I want to access my github repo from two different computers, using one github account. Everything works fine on the computer that I created the repo on. It's just this second computer that is messed up
I successfully set up a repo on github. Now I want to clone it on another machine so that I have push/pull access.
I made a public key on the second machine and specified my email as the email associated with github
ssh-keygen -t rsa -C "MYEMAIL#gmail.com",
then copied it to the SSH keys on the github website.
I cloned the repo like this
git clone https://github.com/MYUSERNAME/MYREPO
Next I edited the "url = " line in the .git/config file so that it said
url = ssh://git#github.com/MYUSERNAME/MYREPO
Both of my computers are configured to have the same user.name, USERNAME and github.user based on my github account settings. I also configured the API token with the same token on each computer.
git config --global user.name "FIRST LAST"
git config --global user.email "MYUSERNAME#gmail.com"
git config --global github.user MYUSERNAME
Yet, when I try to push, this happens:
>> git push origin master
Permission denied (publickey).</code>
fatal: The remote end hung up unexpectedly
The issue was a naming one, as the OP erin mentions in the comments:
I named my public key "github.pub" rather than "id_rsa.pub"
For ssh to work, using default naming convention is important.
See, for instance:
"git clone with ssh issue"
"GITHUB setup - no address associated with name"
I have setup with guthub with a previous github account on this computer called myaccount when i run this command
ssh -T git#github.com
Hi myaccount! You've successfully authenticated, but GitHub does not provide shell access.
Ok but i have now setup a new github account called samaccount but i cant run this command i get this error.
git push -u origin master
i get this error
ERROR: Permission to samueleast/Samuel-East-S3-Audio-Playlist-Player.git denied to myaccount.
I dont want it to use myaccount it should be using samaccount !!!
i have followed all the steps here http://help.github.com/mac-set-up-git/
setup brand new ssh key.
and also run this command many times
git config --global user.name "samaccount"
but it still uses myaccount its sooo annoying where am i going wrong???
GitHub recognizes you as myaccount because SSH is using a key that corresponds to a public key that has been added to the myaccount account on the GitHub website.
If you want to switch entirely to using the sameueleast account instead of myaccount, you can do the following:
Login to GitHub's website as myaccount
Go to "Account Settings"
Go to "SSH Public Keys"
Delete your public key from that list
Logout
Login to GitHub's website as samueleast
Go to "Account Settings" -> "SSH Public Keys"
Select "Add another public key" and paste in the contents of your public key. You public key will (probably) be called id_rsa.pub or id_dsa.pub and be in your .ssh directory.
On the other hand, if you want to be able to use either myaccount or samueleast when pushing to GitHub, you will need to create aliases for git#github.com in ~/.ssh/config, such as:
Host github-myaccount
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_dsa-myaccount.pub
Host github-samueleast
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_dsa-samueleast.pub
That assumes you've generated a second SSH keypair and given them names as above. Then you need to make sure that you are using the appropriate alias in the URLs of your git remotes. For example, if you want to change your origin remote so that pushing to origin means "pushing to origin as samueleast", you could do:
git remote set-url origin \
git#github-samueleast:samueleast/Samuel-East-S3-Audio-Playlist-Player.git