This forces git to use a specific key for an entire domain, which usually won't work. For example, if someone has a personal github account as well as a work account, this configuration will break one of them. Show 11 more comments. Flimm Flimm 8, 5 5 gold badges 26 26 silver badges 36 36 bronze badges. I had to export the shell variable to an environment variable to make this work, i.
Abdull In Bash, doing the assignment on the same line as the command exports the environment variable for just that command. Show 15 more comments. However, there are still a few ways to achieve your goal: Option 1: ssh-agent You can use ssh-agent to temporarily authorize your private key. Host github. I've allowed me to reformat this post: IMO this is by far the most comprehensive answer. In its original design, a quick scan suggested the post where describing a single complicated solution to the problem, so I missed it.
Show 4 more comments. This is the answer I was looking for, as I have separate GitHub accounts for home and work. I just had to set Host work. It still connects to "github. The URL for details " itblog. CarlSmotricz the original one was moved here: medium.
Every other answer misses how you can set the host when you add the origin, which automatically allows git to use the correct key file. Nice, that was what I was looking : — Lucas D'Avila. Show 7 more comments. Ignacio Vazquez-Abrams Ignacio Vazquez-Abrams k 8 8 gold badges silver badges bronze badges.
Another explanation of how to do this. I work on a machine A from which I git push to a server B that only accepts ssh key authentication. This is just great, didn't know about this. Thanks for the answer, quite helpful as well in puppet environments, to prevent the extra hassle to manage. This solution does not work together with the --recursive flag. The submodules are not fetched using the specified key and therefor fails if they require auth.
Each submodule is an entirely different repository, with their own set of remotes. They're glued together by Git for your convenience, but in no way remotes for a submodule are tied to the ones in the parent repository. I'm afraid that you must set the remote using the ext transport in each submodule for recursion in the parent to work. Basically, the git-remote-ext remote helper which supports "ext::ssh example. This normally isn't ever a concern because user always sees and trusts the URL they pass to git.
However git submodules, through the. Show 9 more comments. Clone your repo using the appropriate host. Even safer alternative, which would prevent any possible conflict with anything in your default config file plus explicitly mentioning the port to use would be:!
Jan Vlcinsky Jan Vlcinsky 3 3 silver badges 10 10 bronze badges. PiotrFindeisen Thanks for your note. However, I do not understand it completely - in zsh it helps me to keep strings with space in one piece, but in bash not.
Can you tell me more or point to some explanation? I do not want to add some modification blindly. You should remove the first half of your answer. No one's interested in a solution that doesn't work, and it's wasted reading that obfuscates the correct answer at the bottom, which works wonderfully. Cerin If you mean removing the "Error to avoid" I am going to keep it there. It shares common pitfall to avoid and it is very short.
I am sure, someone would try optimizing the solution by providing all the things into variable this happened to me , so I tried to shorten the path to success. Brendan Baldwin Brendan Baldwin 91 1 1 silver badge 4 4 bronze badges. My solution was to add this to my. Michael Cole Michael Cole 4 4 silver badges 7 7 bronze badges. You can just use ssh-ident instead of creating your own wrapper. Community Bot 1. Simply pair server addresses with the keys you want to use for them as follows: Host github.
Zaz Zaz 2, 2 2 gold badges 21 21 silver badges 35 35 bronze badges. My solution was this: create a script:! Salsicha Salsicha 31 1 1 bronze badge.
This was my mistake: "If you already have a remote set up Thanks a lot!!! Dmytro Buryak Dmytro Buryak 21 1 1 bronze badge.
Just use ssh-agent and ssh-add commands. Just type git clone git github. You need to execute the above command after you reboot your machine. Run5k 15k 23 23 gold badges 45 45 silver badges 61 61 bronze badges. Jinmiao Luo Jinmiao Luo 19 3 3 bronze badges. Please explain the process including How can I create an agent — Srikrushna. Sounds smart, - but maybe a little to good to be true, considering how clumbsy all the other answers are.
I couldn't get this to work. Zeth You may have a problem when creating the ssh agent. If you are using MacOS, you only need to execute ssh-agent. Active 2 years, 3 months ago. Viewed k times. I tried "git config --get-all", but I get the error message error: wrong number of arguments; usage: git config [options]. Peter Mortensen 29k 21 21 gold badges 97 97 silver badges bronze badges. Kai Schneider Kai Schneider 1, 2 2 gold badges 12 12 silver badges 27 27 bronze badges.
Add a comment. Active Oldest Votes. For example, when using GitHub: ssh -v git github. How does this work on Windows where there is no default command line ssh client to run? Just make sure this optional feature is activated Search for "Manage optional features" in Windows.
MewX MewX 3, 1 1 gold badge 26 26 silver badges 37 37 bronze badges. Thanks for simple and easy solution!! Stephan Hogenboom 1, 2 2 gold badges 14 14 silver badges 27 27 bronze badges. I've added everything into TortoiseGit, and it worked fine, but Git Bash wasn't picking it up even though the keys were in the correct directory.
It turns out I had to do this from Git Bash:. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Ask Question. Asked 11 years ago. Active 6 months ago. Viewed 1. Improve this question. Peter Mortensen 2, 5 5 gold badges 23 23 silver badges 24 24 bronze badges. Instead for "git" it passes up all the private keys, which are the exact same that work with "root" and asks for a password.
This is a Centos 5. It should be chmod , and should be owned by the git user. If it's owned by the root user, it wont work — Dan McClain. Add a comment. Active Oldest Votes. Improve this answer. I just installed git-for-windows, I am running it from cmd. Thanks, JP.
Second paragraph was golden. That is the file name, it is not a directory — Dan McClain. Show 17 more comments. Oct Oct 1, 1 1 gold badge 8 8 silver badges 5 5 bronze badges. This is what I was looking for since I'm trying to use the Windows command prompt, not git bash.
Nice, easy fix but it would have been hard to figure out without this! Oct's solution did the trick for me. Show 2 more comments. A screenshot is below:. Additionally if you need to convert your private key into '. It worked for me.
A much easier solution is to set everything up working properly in git using openSSH , and then tell TortoiseGit to use the ssh. See stackoverflow. You're done! From Git Bash, do the following to test: ssh someuser someserver. Hugh Perkins Hugh Perkins 1, 7 7 silver badges 9 9 bronze badges. Don't create keys without passphrases. It's like putting your password in a text file, except that everyone knows the default location for private keys. You're answering the wrong question.
The Q is how to point to an existing private key. GregB, I look at it like this: any server for which I create a password-less key is as secure as my laptop, it's an extension of the security perimeter of my laptop.
Actually, not even, since my home directory is encrypted ;- So, it's as secure as the encrypted home partition on my laptop, which is 'good enough' for securing access to github, in my opinion. GregB Don't fall down into paranoia!
I've seen many guides, that encourage users to use password-protected keys, but I have never seen any claiming, that using them without passwords is not secure at all. Plus: some systems doesn't support solutions for remembering key's password, entered by users, and asks for it, each time key is used. Which makes using SSH keys pointless in this situation. For the sake of the conversation, which has deviated from the original question, SSH keys are certainly more cryptographically secure than passwords, but that security is put at risk by not encrypting your SSH keys.
My personal approach is to unlock my keys at the beginning of the day using an SSH agent, which then keeps the decrypted keys in memory so that I don't need to re-enter the password throughout the day. Show 4 more comments. GregB GregB 1, 2 2 gold badges 13 13 silver badges 21 21 bronze badges. I did this but for github. I prefer this way, because this allowed me fast connect existed keys from other PC — Kirill Husiatyn.
Under which sections should I put these hosts? Jono Jono 2 2 silver badges 2 2 bronze badges. Thank you!! In my case I was using Git for Windows in the Docker container windowsservercore. Community Bot 1. Declan Shanaghy Declan Shanaghy 1 1 silver badge 5 5 bronze badges. I stated above that I'm using Git for Windows and am using ssh.
There must be some standard practice for adding a private key, I just can't seem to find out how. While switching software may indeed allow me to log in, there has to be a way to do it with the standard Git setup, no? Sorry i dont work on windows, only linux. But the key does have to be in your SSH agent.
Yeah, setup was cake on the linux side.
0コメント