SSH Demystified in Windows
Private keys location
This is why is so confusing.
If you installed Git, and SSH that comes with it, the keys should be in ~/.ssh
. But, very often -
they’re not. Start a Git Bash
and it will search for it in home dir. If you start a standard
cmd.exe
it will look for it in Git’s install directory (.../Git/.ssh
).
You can unify this strange behavior by using HOME variable.
setx HOME -your-home-dir-s
For TortoiseGit, everything is totally different.
Specify multiple private keys
But without any authentication agent.
On a temporary, per command basis, you can use ssh -i
switch:
ssh host -i /var/root/.ssh/id_rsa
Put it in ~/.ssh/config
file.
For a permanent solution, add the following option (with path) to your ~/.ssh/config
IdentityFile /var/root/.ssh/id_rsa
It is possible to have multiple identity files specified in configuration files; all these identities will be tried in sequence. So, just add above line to your config.
More advanced setup in config
Put the following content in a file “%HOMEDRIVE%%HOMEPATH%.ssh\config”
set F="%HOMEDRIVE%%HOMEPATH%\.ssh\config"
echo. >> %F%
echo Host fbm >> %F%
echo HostName um-1764.conepuppy.com >> %F%
echo User vcolovic >> %F%
echo Port 4322 >> %F%
echo IdentityFile ~/.ssh/id_rsa >> %F%
But, it reads from another directory, so move it there: mv “%HOMEDRIVE%%HOMEPATH%.ssh\config” “%PROGRAMFILES(X86)%\Git.ssh\config”
Very important:
This is the one + plus permanent (on a user level, no /m switch):
set HOME=%HOMEDRIVE%%HOMEPATH%
setx HOME "%HOME%
Now, I believe, even Git will use the right directory. GitHub is already ok.
And, how to find out if it’s wrong?
Just type ssh-keygen
and wait to see where it will suggest to save a file.
One small utility is:
ssh-keyscan um-1764.conepuppy.com -p 4322
Just redirect output of this command to a ~/known_hosts
Set up SSH for Git - Bitbucket - Atlassian Documentation - Confluence Getting Started with Git and GitHub on Windows - Kyle Cordes
Setting up multiple GitHub accounts on Windows - Kevin Pelgrims
I found this in: “c:\Program Files (x86)\Git\cmd\gitk.cmd”
@rem Get the abolute path to the parent directory, which is assumed to be the
@rem Git installation root.
@for /F "delims=" %%I in ("%~dp0..") do @set git_install_root=%%~fI
@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%PATH%
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%