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

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.

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

How to update SSH passphrase in vscode?

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.

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.

Github: I have to make a new SSH key after every use

I have a school and a personal Github, so I made an SSH key for my personal account and linked it up. It always works only once, then gives me
Push Failed
Git#github.com: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
It works fine again after I delete the old SSH and make a new one, but this is obviously a huge hassle. I am on Windows 10, using Git Bash, and IDE is IntelliJ.
Any ideas? Thanks.
I solved this problem in the following way:
1.Create a file named config in the path $USER_HOME/.ssh/, then add following content.
# For school account
Host school_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_school
# For personal account
Host personal_github
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
2.Run following command using git bash:
Change your school github repository configuration
git remote rm origin
git remote add origin git#school_github:your_github_username/your_repo_name.git
You can hava a try.
You don't need to create SSH keys for each git service just upload the same public key to both personal and school accounts and it will work.
SSH public key is tied to you local account you have generate SSH keys only if you are using different local(machine) account or different machine
Seems to me like when you try to authenticate, you are probably not using your keys.
If you run the command
ssh-add -l
You (should) see a list of all your keys. Each time you start a new session, make sure to start up the agent and add your keys.
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa

can't able to perform git push, permission denied?

I already made a repository in github as wordpress-template.
I created a .git repository locally, added some files there, and committed it.
Then I created a remote as origin and give it the url of the github repository as:
git remote add origin git#github.com:squalporeover/wordpress-template.git
Now I want to push my master branch to that repository. I ran the following command:
git push origin master
But it shows:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
It looks like you added the SSH version of the remote URL. In order to use this you need to set-up Github with SSH.
Otherwise use the HTTPS version of the clone URL which will ask for your username and password:
You need to use ssh-keygen to generate an ssh key pair.
See: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
Duplicate found here: Git - Permission denied (publickey)
This worked for me:
Step 1- git remote rm origin
Step 2-select the http option in github
step 3- run the following command again
git remote add origin https://github.com/yourdirectory/link.git
git branch -M main
git push -u origin main