There are many fine instructions about how to work with git under windows using GitBash.
I note that when git is installed, it offers the option of "set up for using git from the windows prompt", which puts git on the windows path.
Is there some way to set this up so that ssh authentication works?
At the moment I get "permission denied (publickey)" when I try to do git commands that access the remote.
(edit) I have set %HOME% to point to my Windows home directory, and there is a .ssh folder in there with id files that work under a gitbash shell.
I appreciate that the answer is likely "no, this is why GitBash exists". But - it would be good to know for sure.
If the answer is "no" it kinda makes you wonder why you would bother putting git on your windows path?
ssh access works fine from a regular DOS session.
You only need to define C:\Users\YourAccount\.ssh and add your id_rsa and id_rsa.pub there.
Launch your git session through git-cmd.bat, which will define %HOME% to your C:\Users\YourAccount: that is what will make ssh work.
This should put your msysgit/bin installation in your PATH.
I really recommend not installing through a msi (Microsoft Installer), but through a simple unzip of an archive (portable version "PortableGit-x.y.z-preview201ymmdd.7z")
And the OP GreenAsJade's comment points out the fact that GIT_SSH must point to plink.exe.
Well, maybe I have a process that seems to work.
If you use a passphrase during the generation of the keys, you'll have to type this passphrase after loading an ssh-agent and add the key to the agent.
Basically, the solution is: follow the instructions on this page:
https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
BUT, during the generation of the keys DO NOT TYPE A PASSPHRASE.
Obviously, it's 'weaker' from a security point of view.
But, the .bashrc script will work as expected (loading the identity on git bash startup).
You can use then the "start-ssh-agent.cmd" script located on Git\cmd folder. It will open a Dos Prompt with the identity loaded and everything will work!
Related
The documentation says plain as day that VSCode does not come with git, that it leverages your machine's git installation and you must install it.
HOWEVER, it worked just fine for me. I only had github desktop and I am absolutely positively sure that I did not have git for windows installed and github desktop did not place itself in my PATH. (Technically I did have git on Bash on WSL but I know vscode isn't/can't access that). And yet it worked just fine for the longest time.
So, my question is, did vscode come with its own git executable? I ask because ever since I set up 2 factor auth on my github account I've been having to manually log in each time I push, it doesn't use my SSH keys stored in username/.ssh like git shell does.
Github Desktop installs git for you, typically located "C:\Program Files\Git", which is what VSCode, in your case, is most likely using.
If you refer to the answer from this post:
VSCode Terminal + Git Bash "command not found" for any command
it shows the settings (settings.json) that you need to add to allow for git bash and login to be used.
Hopefully this helps!
I tried to do hg to a remote server (hg pull or hg push). Failed on Windows, but succeeded in OS X. I used the same ssh private and public keys for Windows and OS X. Here are the details:
On Windows, I used cygwin, for which I also installed openssh. The private and public keys are inside .ssh folder of cygwin home (/home/simo/.ssh). When I did, say, hg clone ssh://simo#url in cygwin, a popup windows of title TortoisePLink appears and asks me to enter Password, which, I believe, means the passphrase of the ssh key. I entered, and it immediately asks me to enter it again and again (the same popup window). I double-checked the password, of course. If I keep entering the password 5 times, then it stops and says Too many authentication failures for simo and abort: no suitable response from remote hg!.
Ironically, if I don't use Cygwin, but use Command Prompt, I still run into the same issue. This may be the key to understand the issue, because I am not sure the ssh used in command prompt is the same as the ssh used in cygwin, and therefore the ssh key does not seem to matter in either case. First, I only stored the key for .ssh in cygwin, I ran into the problem. I tried command prompt (without copying the ssh keys to there), I also ran into the problem, so looks like the ssh key is not used at all during the hg. I then tried copying the key to the home dir of command prompt (C:\Users\simo\.ssh), I also faced the same issue.
I copied the ssh keys to my Mac OS X, put them inside .ssh, and run. Everything works fine. Any idea why I failed on Windows with hg ssh? Could the problem is because if Cygwin? Because the ssh keys are not used/not found? and why the heck the popup window with title TortoisePLInk keeps asking me for password?
On Windows you can have two different formats for ssh keys:
if you use Cygwin and openssh the format is similar to Unix one
if you use PuTTY/Pageant (ssh agent) the format is different
So you have to choose which one you want to use. Note that you can "import" you Unix format keys into a Pageant agent, this should then work right out of the box with Tortoise.
But you can also configure in mercurial.ini to use the Cygwin ssh (see for instance this answer: https://stackoverflow.com/a/18973676/236726)
Hope it'll help.
I wanted to try and use git in my regular Windows prompt instead of in Git Bash. Simply for the reason that I could then use the terminal that IntelliJ provides. I figured it to be a 1 minute fix but I guess not.
When I try to git pull origin <branch> I get the following error message:
C:\Users\Username\Documents\Bitbucket\java-project>git pull
Could not create directory '/c/Username/.ssh'.
The authenticity of host 'bitbucket.org (131.103.20.167)' can't be established.
RSA key fingerprint is 12:8c:1b:f2:6d:14:6b:5c:3b:ec:aa:46:46:xy:7c:40.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/c/Username/.ssh/known_hosts).
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have set the permissions on the existing .ssh folder such that all Users have full access, administrators and SYSTEM. So that should be okay.
I also tried to run the prompt as Administrator to see if that was the issue but that's not the case either.
What I do notice now is that it says: Could not create directory '/c/Username/.ssh'.. However, my .ssh directory is located at C:\Users\Username\.ssh. I might need to change my configuration then.
Git version: 1.9.0.msysgit.0
Windows version: Windows 8.1
First of all, tested with msysgit 1.9.2, when one selects to make just git command available from cmd.exe during installation (where other choices are, make it avaiable only under git bash, or make all MSYS commands available under cmd.exe), git clone works from cmd.exe prompt.
The ssh client uses HOME environment variable to find .ssh/ directory, but git should take care of all the ugly details. You should not have HOME defined in your normal Windows environment, so if echo %HOME% in cmd.exe prompt prints a path, edit the OS environment variables and remove HOME.
If that does not solve it, uninstalling and installing latest version might help.
Finally, you have paths like C:UsersUsername, it probably means you're missing quotes somewhere. In git bash, try these two commands to see:
echo C:\Users\Username
echo 'C:\Users\Username'
Make sure you type your cmd session the git-cmd.bat which comes with every Git For Windows msysgit release.
That will set your HOME to %USERPROFILE%, which should be C:\Users\Username.
But make sure you didn't have an environment variable HOME already defined with an incorrect value: unset it if that is the case.
Open Git Bash console.
Perform the command below to enable read and write;
chmod 776 your local path here/known_hosts
More details here
I would like to create either a script that can be executed or an application that will clone several GIT repositories for offsite data backup purposes.
I need this to be able to run on a Windows 7 machine (I'm sure this will add to the complexity of this problem).
I tried using GIT bash (MINGW shell) and using C# to create the shell and invoke commands to it. My tester was working fine until it attempted to supply the password. It appeared that the password prompt was coming from yet another terminal instance as stdin and stdout were not longer to read and write to the console.
Ideally I would like maintain a simple bash script that could be launched and clone the repositories but I was not able to find anything like that for Windows.
Any help or insight would be greatly appreciated.
The ssh keys should be created with no password. Ensure authorized keys file is updated on the machines you're connecting to.
Install msysgit and add the proper keys. I'm doing this without any issues. Make sure to set msysgit to not alter the line endings during it's install. You can change that later with git config if you forget. Use ssh and not putty.
Msysgit will give you bash on windows.
Hope this helps.
So I thought I had finally got everything setup on Windows ... then ran into this issue.
Current setup
URL: ssh://user#host:port/myapp.git
Already run Putty - and can connect using valid .ppk keys through the ~/.ssh/authorized_keys direct. In Git and TortoiseGIT - I set both to use "plink.exe".
Putty works fine - no issues - but when I run that URL into bash I get for a git clone (url)
fatal: the remote end hung up expectedly
In a cygwin bash terminal - running "ssh user#host" - works no probs at all.
Anyone suggest anything?
I found out that using ssh.exe from the Git package works every time, as opposed to the ssh that comes with cygwin (the default).
Using this exported variable seems to help; it's slower (2x or more) but it's more stable. Take it as another workaround.
$ export GIT_SSH=/cygdrive/c/Program\ Files/Git/bin/ssh.exe
FYI:
This version of Msysgit comes with OpenSSH 4.6p1, OpenSSL 0.9.8e. [works]
Cygwin's SSH is OpenSSH 5.5p1, OpenSSL 0.9.8n. [doesn't work]
I had the same problem with plink for git under windows.
On run of plink.exe -v xxx#host.com it started to show
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
login as: <<< trouble
Instead of
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
Using user "xxx"
To resolve this problem I cleaned up the putty registry records and sessions by
putty.exe -cleanup
After that plink starts afresh and asks to trust and store the host again and it is getting connected with no problem !
Try following steps, maybe something will give you a hint on your problem:
1. Run putty and after setting up server name/user name/keys etc. save those settings.
2. Run plink.exe or plinkw.exe like plink.exe user_name#server, (it'll throw some info at you) just to see if plink can connect to the server.
3. Check again that git knows that it should use plink, I'd say with all VCSs, that's the problem people have most often, apart from their keys not being set up properly.
Normally by now most of your ssh problems would be revealed. Now just fix them. :)
Update:
I think the problem you have is caused by several gits you've got installed. For the msysgit and cygwin git you'd need to set the GIT_SSH variable. That's done via either 'set GIT_SSH=c:\path\putty\plink.exe' or 'export GIT_SSH=/your/path/putty/putty.exe' respectively. If you're also using tortoise git, you'd need to locate 'properties' (or is it settings?) in it's menu, and set the ssh client there.
Apart from all that, when specifying git clone URL, use your login name and the server name in there, e.g. 'git clone ssh://user#server/your/path/repo.git User and server names should be used by plink, and plink should be able to connect to the server with those arguments, when all of those requirements are met, you'll be all set.
Good luck.
If you want to try the cygwin openssh 5.4p1-1, which does seem to work for this, unlike 5.5 or 5.6, you can use the cygwin time machine mirrors. Start setup.exe with -X and add a mirror Url, such as:
ftp://www.fruitbat.org/pub/cygwin/circa/2010/05/20/230133
Be careful not to install too much, i.e. base packages, from an older mirror than the rest of your install.
We had same problem and here is solution how we solved the problem:
at first we got:
zajdan#cyberFuture:~$ git clone ssh://nette#19X.16X.14X.7X/~repos/erotika.git/ erotika
Initialized empty Git repository in /home/zajdan/erotika/.git/
Password:
fatal: '/repos/erotika.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly
zajdan#cyberFuture:~$
solution:
zajdan#cyberFuture:~$ git clone ssh://nette#19X.16X.14X.7X/~/repos/erotika.git/ erotika
after tilde there must be a slash!
I have exactly the same issue.
I don't use Putty (just Cygwin).
I use Windows 7 Ultimate (fully patched as of this moment).
I just installed Cygwin yesterday.
I made sure binary mounts were being used.
If I copy a git repo to the machine (via samba mount), I can clone it, but when I "git diff" after the clone, there are a bunch of "different" files with no diffs. After a "git status" there was no output from "git diff". It seems like a newline thing, but I can't figure out how that would be happening. (I have igncr in SHELLOPTS, but removing that doesn't fix it.)
I'm completely stumped.
Check the openssh version you're using in CygWin. Version 5.5p1-1 (which is the latest at this time) gave me the same error. Downgrading to 5.4p1-1 fixed the problem.
Another solution would be to use putty/plink instead of openssh.
For more details, see this thread: http://www.mail-archive.com/cygwin#cygwin.com/msg103752.html
I get message: "remote end gung-up, unexpected EOFs, index-pack failed" while cloning git repo but was able to workaround this issue with copssh http://sourceforge.net/projects/sereds/files/Copssh
The root cause is Cygwin openssh package.
I removed original openssh from Cygwin, installed copssh and set GIT_SSH variable to point copssh binaries. After this I simply added copssh binaries in the PATH and now I'm using copssh instead of openssh - there is no difference.
Everything works fine and issue does not appear any more.
The other solution is to use mSysGit package.
I believe the real problem is that cygwin's ssh looks for .ssh in /home/name/.ssh and mingw's git ssh looks for .ssh in c:/user/name/.ssh
Chances are your keys are in one and only one of these directories.
You can trying telling cygwin's .ssh to use a different identity file using the -i switch, or move the keys into both directories, or create an ssh config file in /home/name/.ssh/config.
I created a config that contains:
Host github.com
User jerryasher
Hostname github.com
IdentityFile c:/Users/jerry/.ssh/id_rsa
And given that I can use either the mingw git from git bash or cygwin's git from an rxvt to interact with github.
To correct this issue, run "plink -agent github.com"
Press y when prompted to cache the key. Login as git. You'll automatically be disconnected. And it sould work.
Source: http://devlicio.us/blogs/sergio_pereira/archive/2009/05/06/git-ssh-putty-github-unfuddle-the-kitchen-sink.aspx
Try to use absolute path to repo in a URL, that worked for me.
Instead of:
git ssh://user#host:port/myapp.git
Write:
git ssh://user#host:port//home/user/repo/myapp.git
Notice the double slash!