vscode not connecting to multiple gitlab accounts using their respective ssh keys - visual-studio-code

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.

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

git push to github in a batch job sumitted to a server using qsub

I set a ssh-agent and gave it an id_rsa key, so I don't have problem using git command on a terminal of a linux server to update to github, but when I try to do this by a bash script using qsub to submit the job to the server, I got the following error messages,
On branch master
nothing to commit, working directory clean
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
my shell script is,
#!/bin/bash
git add *.png
git commit -m "upload_fig"
git push
I also set ~/.ssh/config like the following,
Host remoteHost
ForwardAgent yes
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Anyone knows how to solve this issue?
Thanks!
In addition: I have set id_rsa key to github and I can use git command on the local terminal.
What you are looking for might be in what you are looking for might be in this. I'm guessing you didn't add your public key, ~/.ssh/id_rsa, to your github account.

Can't push to GitHub after enabling two factor auth [duplicate]

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?
If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.
In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)
As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git
Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>
You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys
for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)
Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push
You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.
Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]

Pushing to GitHub without a key

I am using GitHub and C9 on a work computer and but GitHub will stop reading my SSH key after a few hours. IDK if it is because I am using my work computer (job is not currently programming), but is there a way I can push my code without an SSH key
First, check that your remote URL is indeed an ssh one:
cd /path/to/my/local/cloned/repo
git remote -v
If it is (git#github.com:user/repo), check what ssh -Tv git#github.com returns.
If SSH does not work (because SSH port might be blocked at work), switch to an HTTPS URL:
git remote set-url origin https://github.com/user/repo
From there, make sure git config credential.helper does reference an helper (like "manager" on Windows), and you will be prompted for your GitHub account username/password at the first push. After that, your credentials will be cached.

Push to GitHub without a password using ssh-key

I generated an SSH key pair without a password and added the public key to GitHub.
Connection with
user#dev:/var/www/project# ssh -T git#github.com
Hi User! You've successfully authenticated, but GitHub does not provide shell access.
was successful and when I rename the key, it fails.
But when I want to push my changes, it stills ask me for my username and password combination.
Is there a way to push without a password?
If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.
Change it to ssh.
For example, a GitHub project like Git will have an HTTPS URL:
https://github.com/<Username>/<Project>.git
And the SSH one:
git#github.com:<Username>/<Project>.git
You can do:
git remote set-url origin git#github.com:<Username>/<Project>.git
to change the URL.
In case you are indeed using the SSH URL, but still are asked for username and password when git pushing:
git remote set-url origin git#github.com:<Username>/<Project>.git
You should try troubleshooting with:
ssh -vT git#github.com
Below is a piece of sample output:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_dsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Yuci/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
I actually have already added the public key to GitHub before, and I also have the private key locally. However, my private key is of a different name called /c/Users/Yuci/.ssh/github_rsa.
According to the sample output, Git is trying /c/Users/Yuci/.ssh/id_rsa, which I don't have. Therefore, I could simply copy github_rsa to id_rsa in the same directory.
cp /c/Users/Yuci/.ssh/github_rsa /c/Users/Yuci/.ssh/id_rsa
Now when I run ssh -vT git#github.com again, I have:
...
debug1: Trying private key: /c/Users/Yuci/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
...
Hi <my username>! You've successfully authenticated, but GitHub does not provide shell access.
...
And now I can push to GitHub without being asked for username and password :-)
As usual, create an SSH key and paste the public key to GitHub. Add the private key to ssh-agent. (I assume this is what you have done.)
To check everything is correct, use ssh -T git#github.com
Next, don't forget to modify the remote point as follows:
git remote set-url origin git#github.com:username/your-repository.git
Additionally for gists, it seems you must leave out the username
git remote set-url origin git#gist.github.com:<Project code>
You have to use the SSH version, not HTTPS. When you clone from a repository, copy the link with the SSH version, because SSH is easy to use and solves all problems with access. You can set the access for every SSH you input into your account (like push, pull, clone, etc...)
Here is a link, which says why we need SSH and how to use it: step by step
Git Generate SSH Keys
for using SSH you must use $ git remote add origin git#github.com:USERNAME/REPOSITORY.git instead of git remote add origin remote_repository_URL.
you can check it with $ git remote -v, if you see 2 lines in the below format, it will work correctly:
origin git#github.com:username/repo-name.git (fetch)
origin git#github.com:username/repo-name.git (push)
Like the other users mentioned, you must convert it from using HTTPS to SSH. I don't see an answer with an end-to-end solution. After setting up the ssh keys, do (on your local machine) :
$ git remote set-url origin git#github.com:username/your_repo.git # Convert HTTPS -> SSH
$ ssh-add ~/.ssh/id_rsa_github # add private github ssh key ssh-agent (assuming you have it already running)
$ git push
You did everything ok but git still asking by password, this worked for me, execute the next commando in your current project's path:
~ ssh-add -K ~/.ssh/id_rsaYourIdRsa
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsaYourIdRsa in the command with the name of your private key file.
Using the command line:
Enter ls -al ~/.ssh to see if existing SSH keys are present.
In the terminal is shows: No directory exist
Then generate a new SSH key
Step 1.
ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
step 2.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): <here is file name and enter the key>
step 3.
Enter passphrase (empty for no passphrase): [Type a password]
Enter same passphrase again: [Type password again]