Is the ssh key used once? - github

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.

Related

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

Cannot use git to clone in remote web server

I have created a Github repo to where I push my local changes using Git Bash, without any problems. I can also use Git Bash to connect to my remote web server (shared hosting) and navigate to the folder where I want to clone my Laravel site.
This is where the problems begin. When I do
$ git clone git#github.com:myusername/mylaravelsite.git
I get the error message:
Permission denied (publickey)
After some searching for a solution I found that I should make sure that I have a key by doing this:
$ eval "$(ssh-agent -s)"
Which gave this answer:
Agent pid 122372
Then according to the instructions I should do this
$ ssh-add -l
Which gave me this message:
The agent has no identities
Reading up a bit more I try to add the key again by doing
$ssh-keygen -t rsa
...which generated a key pair that I added with ssh-add, I was prompted for a passphrase which I entered twice.
Now, I still get Permission denied (publickey) when I try to access my github repo with ssh. I should also mention that I have created a new SSH key at the github account where I pasted the key I created (I opened .ssh/id_rsa-pub with notepad and copied the content).
What more can I try?
Finally found the answer in case anyone else has the same problem. It turns out that the public key also must exist in the remote web server (in the .ssh folder I uploaded the same rsa_id and rsa_id.pub files, that I created locally), not only locally and in the Github account.
Once I had figured that out and uploaded those files to the webserver, it worked to clone my github repo :-).

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.

Can't push to git

Once I had an old github account, and I'm trying to create a new one and push to that one, but I keep running into permission issues:
remote: Permission to <new account>/<new account>.github.io.git denied to <old username>.
I've tried setting the user name + password, going through different procedures to add ssh keys, deleting my .ssh folder, deleting my old repos, everything I can think of, but I can't fix this.
Check first if your URL is actually an SSH one:
git remote -v
If it is an https,... no amount of SSH setting will allow you to authenticate properly.
If it is an https (again), do check your credential helper with:
git config credential.helper
If you see manager, it is possible the wrong credentials are cached.
In that case, you need to remove them.
See "Github remote permission denied".
The other possibility is the presence of 2FA (2 factor Authentication), which would require a PTA (Personnal Access Token) in place of the regular account password.
But again, you can also switch to an SSH URL:
git remote set-url origin git#github.com:auser/arepo.git

Git wont push. Asking for user/pass

I'm trying to push some of my projects to my github account but when i try it wont let me. I was able to push just a couple of days ago and now I cant.
I tried
running
cd existing_git_repo
git remote add origin https://github.com/Ommy/MapTool.git
git push -u origin master
but on git bash it asks for
Username for 'https://github.com':
I try my username/password which doesn't work.
I tried running
git config --global user.name "Fasih Awan"
git config --global user.email *********#gmail.com
but even with that it still asks for the username/password. I created the repository on github before pushing but it still does this. What am I doing wrong?
If you are using HTTP for the remote repository you will still need to type your username and password. If you want to use SSH keys, use the SSH protocol for the remote repository. There is a guide here on how to configure SSH keys.
Either use password caching or SSH. It's all nicely explained here: https://help.github.com/articles/set-up-git
Make sure that you have uploaded your public key to github. The only thing you should be asked for is a password for you public key, not a username.