How to avoid Permission denied (publickey) when pulling from github? - github

I want to connect with GitHub from my server Centos.
I was doing ssh-add ~/.ssh/id_rsa and these problem solved.
But, I don't know why, when I am sign out and then sign in again, the problem shows again.
Anybody know how to solve this problem?

Check exactly what key is used with:
git -c core.sshCommand="ssh -Tv" pull
That way, you will see which URL and key is actually used by your command, and have some clue as to why the current key does not work.
Note that ssh-add is only valid for your current session: signing out/back in would require an ssh-add again. Which is why it is generally part of your .bashrc to automate that step.

Related

Is the ssh key used once?

I have created an ssh key with a passphrase and connected it with github successfully and use the ssh -T git#github.com to test it and it asked me for the passphrase and it worked.
But now when I push or pull anything it doesn't ask me for the passphrase so I thought that the key isn't used, So I deleted it and worked without it and git nor github didn't even ask me for anything, and the work is done.
So my question here is I need to know how to link this ssh key to github and make it ask me about the passphrase of the key whenever I do any thing.
But now when I push or pull anything it doesn't ask me for the passphrase so I thought that the key isn't used, So I deleted it and worked without it and git nor github didn't even ask me for anything, and the work is done.
Check first what kind of URL your local repository is actually using.
cd /path/to/local/repository
git remote -v
If it is an HTTPS one, then Git would not ask anything if your credentials (user account name/token) were already cached in the credential helper (git config --global credential.helper)
That would explain why even deleting the SSH key has no effect in your case.

GitHub ssh keys - ssh test works but using git clone returns permission denied

I've been working on this for a few hours now and I've read everywhere but am officially stumped.
I'm trying to set up ssh keys for a dev-environment to interact with github. I've followed the guide on github and have made the keys and when I test them using the git#github.com it works but when I use git clone git#github.com:username/repo I get
Cloning into 'reponame'...
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.
I've tried adding it to ssh-add and that works, ssh-agent is running and has access. I've looked at the environment variable and set it to ssh among a few other things. I don't know what else to try. Let me know what logs I can post to help.
My thoughts are maybe the git command isn't using the identities or the right ssh client but other than the environment variables I'm not sure what else to change.
Thanks for the help in advance.

Github SSH issue 'Permission Denied'

I am stuck on this annoying (and common) issue running Manjaro (latest). SSH works just fine for me on my local network. I can connect to my file server and pi-hole just fine.
GitHub however is proving more difficult.
gh repo clone User/Reponame gives the following:
WARNING: cgroup v2 is not fully supported yet, proceeding with partial confinement
Cloning into 'Reponame'...
warning: templates not found /usr/share/git-core/templates
The authenticity of host 'github.com (140.82.121.3)' can't be established.
RSA key fingerprint is SHA256:SomeLongNumberBlahBlah.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/USER/.ssh/known_hosts).
Load key "/home/USER/.ssh/id_rsa": Permission denied
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.
exit status 128
Now I tried deleting my known_hosts, checking the file permission, creating new keys for my server/pi-hole and all works fine. I don't see why GH is struggling with permission. I've tried a few solutions but nothing seems to work for me. I've set my global user and email for github, I just can't get passed this step.
ssh -T git#github.com Asked for a passphrase and accepted it when I entered. Yay! I have both keys set and added to github.com via my browser etc. I must be missing something.
Still no change in the clone command. I am honestly stuck having read multiple threads on the subject. SSH always gets me :(

How could I setup a permanent connection to github from server with SSH key?

I followed the guide from https://help.github.com/articles/generating-ssh-keys/ to generate a ssh key used to connect to github from my server.
The problem is if I close the shell and login the server again, I have to repeat below steps to reconnect to github, otherwise the accessing will be denied:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
How can I setup a permanent connection with github?
Since you are logging on to the command-line (presumably using SSH) all applications that you run, including ssh-agent, stop when you log out.
In my opinion your best bet is to have your CentOS machine start ssh-agent for you each time you log in, then manually use ssh-add to add your key. This can be done by modifying your shell's login script. If you are using bash, this file is called ~/.bash_profile. If you are using another shell, refer to its documentation and choose an appropriate file.
Edit one of these files and add eval "$(ssh-agent -s)" at the end.
Now, each time you log in ssh-agent should automatically start, and you can optionally run ssh-add (since you are using a file that ssh-add looks for by default you don't need to pass the file to the command) to add your key, then do Git stuff.
It sounds like you want to automate the adding of the key as well. This isn't something that I would choose to do since I like adding keys to be explicit, but because you don't have a passphrase on your SSH key you should be able to add ssh-add to the same file we modified above (after we start the agent, of course) and have your key added automatically.
Thanks #Chris
I did the following and it worked:-
Step1:- .bash_profile
Step2:- enter image description here
Step3:-source .bash_profile
Step4:- enter image description here

Auto Unload Key From SSH

Why did I get the following error (on the same machine where the github connection had been properly set up before)? Meaning, it worked the previous day (e.g. I could push, pull, etc. with no problem) but didn't the next day.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
When I did ssh-add:
$ ssh-add -l
The agent has no identities.
Is it possible that a key, which was previously loaded into SSH, is automatically unloaded?
The following fixed the issue (for reference):
ssh-add ~/.ssh/github_rsa
Enter passphrase for /Users/admin/.ssh/github_rsa:
Identity added: /Users/admin/.ssh/github_rsa (/Users/admin/.ssh/github_rsa)
The latest Github for (Mac|Windows) include a credential helper (as explained in "How to use git with gnome-keyring integration").
That means, if you need to enter a password (because your private ssh key is passphrase protected), that will be stored by git for the duration of the session.
But at the next session, you will need to enter the passphrase again (once).
On the mac, identities that you add don't usually go away unless you explicitly remove them (ssh-add -d), the machine is rebooted, or you log out and then log back in again.