I copy-pasted a wrong SSH passphrase when prompted for it in VSCODE and it was saved because the "save" checkbox was checked. Now I cannot sync to Github.
Is there a way to update the wrong passphrase in VSCODE? I searched settings and googled but could not find a way.
This is the git log
> git pull --tags origin master
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Edit:
I can commit if I switch from SSH to HTTPS following instructions from https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories. But I cannot commit if I switch again from HTTPS to SSH.
It was probably not VSCode that asked for a password but your authentification agent. Try ssh-add -D in a terminal. ssh-add -l will list "remembered" keys.
I want to disable a working git ssh key. But do not know the owner of the ssh key.
For both disabling the key or removing the user, I would need to know the user details.
The file:.git/config does not include the user information.
And I face the below error when I try to commit
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
FYI: The key is SAML authorized.
Can I know if there is a way we can find the git user using the ssh key?
You can connect to Github using that public key
ssh -T git#github.com
Returns:
Hi githubUser! You've successfully authenticated, but GitHub does not provide shell access.
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.
I use my project at work, but I would like to work with him from home as I can log into my home machine to work with my project.
However, from home, I see the following message:
The authenticity of host 'github.com (ip)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
How can I get past it?
You should simply be able to answer 'yes', which will update your ~/.ssh/known_hosts file.
A better approach, to avoid any MITM (Man-In-The-Middle) attack, would be (as commented below by Mamsds) to verify Github's public key first (see "GitHub's SSH key fingerprints") and, if you find a match, then you can answer 'yes'.
Example:
ssh-keyscan -t ecdsa github.com 2>&1 |ssh-keygen -lf -
256 SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM github.com (ECDSA)
After that, you can use a GitHub SSH URL (provided you have generated the SSH public/private keys, and registered the public one to your GitHub profile)
Note: the ssh key generation should use the base64 old PEM format (option -m PEM), rather than the new current 70 chars OpenSSH one.
See "What is the correct format for private key in Credentials":
ssh-keygen -m PEM -t rsa -P "" -f afile
That or you can switch to an HTTPS URL.
As you are attempting to connect to Github using SSH for the first time (no existing entry for Github in ~/.ssh/known_hosts yet), you are being asked to verify the key fingerprint of the remote host. Because, if an intruder host represents itself as a Github server, it's RSA fingerprint will be different from that of a GitHub server fingerprint.
You have two options.
You may just accept, considering you don't care about the authenticity of the remote host (Github in this case), or,
You may verify that you are actually getting connected to a Github server, by matching the RSA fingerprint you are presented to (in the prompt), with GitHub's SSH key fingerprints in base64 format.
The latter option is usually more preferable.
Just add Github fingerprint to known hosts this way:
mkdir -p ~/.ssh
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
Use one of the following two solutions:
1) Set up the SSH key
Follow the steps discussed on this GitHub help page.
https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
2) Clone using git with HTTPS
Type (copy/paste) the following commands in a terminal on the machine where you would like to clone the repository
git config --global url."https://github.com/".insteadOf git#github.com:
git config --global url."https://".insteadOf git://
You can revert this change using the following commands
git config --global url."git#github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
Try these steps:
Open Git Bash
Check for existing SSH keys:
$ ls -al ~/.ssh
If you already have them, you will see:
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
If you don't, generate one (Press Enter to accept the default file location):
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
To copy the key to clipboard:
$ clip < ~/.ssh/id_rsa.pub
Go to your account on Github/Settings/SSH and GPG keys/New SSH key
Paste your key there
Next, type:
$ git remote
If you see origin, remove it:
$ git remote remove origin
Continue with the last 2 steps provided on GitHub repo page...
$ git remote add origin git#github.com:USERNAME/REPONAME.git
$ git push -u origin master
Refresh your GitHub repo page
Voila!
1- Create SSH key
if you don't have the ssh-key create it like this:
ssh-keygen -t rsa -b 4096 -C "youremail#example.com"
2- Check your SSH key
For this go to your folder ssh, example:
cd ~/.ssh
after that, run this command line : ls
if you have the files: id_rsa, id_rsa.pub so the all is good
now you need to copy your id_rsa.pub ! (⚠️ NOT the id_rsa)
for this run cat id_rsa.pub and copy the result
3- Github / Gitlab
Go to your github / gitlab.
Follow the step by your hosting:
github: Click on your profile -> Settings -> SSH and GPG Keys -> New SSH key
gitlab: Click on your profile -> preferences -> SSH keys
past your id_rsa.pub that you have already copied !
4- If you have already did it and it's already not working ??
When your enter your ssh-key in github / gitlab your key have a Expiration date so you just need to change it
That it ! Have a good work 😀
You just need to type yes and it will work, for more information you can refer to the Official Github documentation. This will give an output saying
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
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