Github ssh key added, checked, still doesn't work - github

I created ssh key as per this tutorial.
Assigned it to the ssh-agent.
Added it to the github account as per this tutorial.
ssh-add -l -E md5
Shows correct footprint
ssh -T git#github.com
Says:
Hi <My username>! You've successfully authenticated, but GitHub does not provide shell access.
But still:
git push
Asks for:
Username for 'https://github.com':
Any idea? Thanks in advance.

Check out this: switching-remote-urls-from-https-to-ssh
High are the changes that you clone your repo over HTTPS and now want to push using SSH.
As suggested on the GitHub site check your remote origin by doing this:
$ git remote -v
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
In case you have https... change it to ssh by doing something like this:
git remote set-url origin git#github.com:USERNAME/REPOSITORY.git

Related

Messed up with deploy key

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

vscode not connecting to multiple gitlab accounts using their respective ssh keys

So for windows, I see the default ssh client config supposed to be placed at C:\Users\Admin\.ssh\config and I use the same, also I am the Admin user.
I added the following ssh client side config:
PS C:\Users\Admin> type .\.ssh\config
Host gc
HostName gitlab.com
User git
IdentityFile ~/.ssh/company_gitlab
Host gp
HostName gitlab.com
User git
IdentityFile ~/.ssh/gitlab_personal
I tested it from Powershell and it is working for both my company and personal GitLab accounts using their respective ssh keys.
PS C:\Users\Admin> ssh -T git#gc
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
Welcome to GitLab, #johnwilson!
PS C:\Users\Admin> ssh -T git#gp
Enter passphrase for key 'C:\Users\Admin/.ssh/gitlab_personal':
Welcome to GitLab, #jwilson!
But when it comes to the vscode, when I try to push or pull changes to the remote repository, the following error shows up for both the company and personal GitLab accounts.
> git push -u gc master
git#gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
> git push -u gp master
git#gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
I tried the suggestion from here as well
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote add origin git#gc:company/infra_code/userlist.git
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote -v
origin git#gc:company/infra_code/userlist.git (fetch)
origin git#gc:company/infra_code/userlist.git (push)
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git ls-remote origin
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
611b36ef47056773c288499cb6974d8671196d78 HEAD
611b36ef47056773c288499cb6974d8671196d78 refs/heads/master
I am confused, so vscode does not pick the default ssh client config C:\Users\Admin\.ssh\config on windows ?.
Or am I missing something?.
Check the remote URL associated with the remote named 'gc'
cd C:\path\to\gc\repo
git remote -v
If the URL starts with git#gitlab.com:..., it won't use the ~/.ssh/config file, and its gc entry.
Change it with the proper URL
git remote set-url gc gc:<me>/<myrepo>
Then VSCode will pick up the right entry, assuming is is running as User Admin.
The OP JohnW confirms in the discussion:
I added an SSH key without a passphrase, which is working for vscode. So this is bug with VSCode cannot connect with ssh key with passphrase?
You need to make sure ssh-agent is activated first.
See "Auto-launching ssh-agent on Git for Windows"
Once the SSH agent is launched (and your private SSH keys passphrase cached in it), you can launch VSCode. It should work then.

Unable to push changes into gerrithub.io

I have the repo here Link to the repo
I cloned it and did some changes but when I try to push it.
It gives me the following error:
$ git push origin HEAD:refs/for/master
Username for 'https://review.gerrithub.io': ardyflora
Password for 'https://ardyflora#review.gerrithub.io':
fatal: Authentication failed for
'https://review.gerrithub.io/ardyflora/virginPulseAuto/'
I have even added the ssh key. Any pointer or help will be appreciated :)
Authentication failure for HTTPS. Better you can take a try with SSH.
Copy the URL for SSH of your repository using a browser and update your local origin.
$ git remote set-url origin <ssh-clone-url>
$ git push origin HEAD:refs/for/master

Still requiring login after SSH authentication

I followed everything in the GitHub tutorial: https://help.github.com/articles/generating-ssh-keys
I did all the commands in the directory of my repository.
I reached the end of tutorial successfully and got the message: "Hi username! You've successfully authenticated, but GitHub does not # provide shell access."
However when I tried to do things such as push it still requested for my username and password.
Check your remotes via git remote -v.
https:// URLs will always ask for a password, unless you configure a credential helper. More info on that in this question.
The simplest solution for password-less git access would be to use the git remote set-url command and set an SSH url for the existing repo.
In your case, git remote set-url origin git#github.com:name/repo.
Then you should be able to git push origin <branch> without being asked for a password.
Good that you have correctly setup your git ssh now you need to reclone the git repository with ssh for example previously you would have done something like this :
git clone https://github.com/dangrossman/bootstrap-daterangepicker.git
this was a https clone now you need to clone with ssh as
git clone git#github.com:dangrossman/bootstrap-daterangepicker.git
you can find the ssh link from your github account same place where you found your https link.
After this you can easily push without your password prompt .
It might though ask for your ssh unlock password. You then need to enter the paraphase you gave during the creation of your ssh key . If you left it blank it might not prompt for it .
I was able to stop the username & password prompt by opening .git/config from the base repo directory and changing the remote URL.
For example:
[remote "origin"]
url = https://github.com/username/my-repo.git
should be changed to:
[remote "origin"]
url = git#github.com:username/my-repo.git
I tried the answer marked as correct but couldn't make it work. This worked for me instead git remote set-url origin ssh://git#github.com/username/reponame

cant add a file into github

I want to add a file into github as follow:
git init
touch test.txt
git add test.tst
git cmmit -m'testtest'
git push origin master
then it will raise this exception:
error: The requested URL returned error: 403 while accessing https://github.com/yacheng1127/YWProject.git/info/refs
fatal: HTTP request failed
then I verify the public key is attached to my github account:
$ ssh -T git#github.com
Hi yacheng1127! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh-add -l
2048 1a:a1:33:26:21:68:7e:9c:26:19:fb:74:a4:d1:6b:bd yacheng1127#gmail.com (RSA)
then I check my remote url:
$ git remote -vorigin
origin https://github.com/yacheng1127/YWProject.git (fetch)
origin https://github.com/yacheng1127/YWProject.git (push)
I don't know where is the problem. could somebody help me? thank you
Use ssh key is used when you use the "git://" url for your remote, you can change this (https://help.github.com/articles/changing-a-remote-s-url).
But "https://" should work too (read/write), but it can't use your ssh key nor ssh agent, you should give git your github login and password :
https://help.github.com/articles/set-up-git#password-caching