Setup git over ssh in Rubymine on Windows - windows

I found a lot of threads about how to setup git over ssh with msysgit and putty/plink, but rubymine seems to use its own git and ssh implementation (see error message below).
Currently I have putty, msysgit, TortoiseGit and rubymine installed. My repository has two remotes:
[remote "origin"]
url = ssh://mygituser#255.255.255.255:1234/path/to/repo.git
[remote "origin_putty"]
url = putty-alias:path/to/repo.git
puttykeyfile = path/to/my/putty/keyfile.ppk
In putty the connection "putty-alias" is defined with the same user, host and port used in origin and also sets the ssh key again (might not be necessary). Using TortoiseGit to push to origin_putty works fine since it loads the putty ssh key and prompts for my passphrase. However, when I'm trying to use origin from rubymine it prompts for the password of mygituser since there is no keyfile defined.
I already tried the following solutions
Setting GIT_SSH to plink, running pageant and loading the key there (no change)
using the puttykeyfile line in the definition of origin (no change)
using origin_putty from rubymine (does not resolve putty-alias)
The reason I think rubymine uses its own ssh implementation is the error message I get on an unsuccessful authentication:
SSH: authentication methods: [publickey, keyboard-interactive, password] last successful method:
java.io.IOException: Authentication failed:
at org.jetbrains.git4idea.ssh.SSHMain.authenticate(SSHMain.java:280)
at org.jetbrains.git4idea.ssh.SSHMain.start(SSHMain.java:155)
at org.jetbrains.git4idea.ssh.SSHMain.main(SSHMain.java:135)
fatal: The remote end hung up unexpectedly

You're right: by default RubyMine uses trilead-ssh2 Java library, and is not aware about Putty settings.
You may switch to using the native SSH in the Settings | Version Control | Git | SSH Executable | Native
But note, that it doesn't work well with passphrases, so if your private key is passphrase protected, you have to use pageant or similar software.

Related

Using VS Code with native Windows OpenSSH client

I'm trying to pass from Putty/Pagent/plink to Windows OpenSSH native client.
I already managed to do this in TortoiseGit, but with the main problem with VSCode seem to be I can't set which ssh agent to use.
I enabled the OpenSSH agent service on Windows to start automatically and added my open ssh key with ssh-add.
Every time i try to push from VSCode all i got is an error message with
Git: FATAL ERROR: Disconnected: No supported authentication methods available (server sent: public key)
When trying to push from terminal I got also
Please make sure you have the correct access rights and the repository exists.
As already said, with TortoiseGit I have no problem at all, and the only differences are that in TortoiseGit I set the ssh-agent.
you might need to confirm your System environment variable GIT_SSH points to the ssh within Git: C:\Program Files\Git\usr\bin\ssh.exe
You may need to update your Windows OpenSSH. If you run ssh -V from a PowerShell window and see OpenSSH_for_Windows_7.7p1, this is probably the case. The instructions for upgrading are available in the Install Win32 OpenSSH Wiki.
General
VS Code uses the Windows version of OpenSSH.
The config file that you change in VS Code is located in /Users/<username>/.ssh/config
The default location/name of a key is at /Users/<username>/.ssh/id_rsa.
Example
Local: Windows 10 machine with VS Code and the very awesome Remote - SSH extension installed
Remote: Ubuntu, where I use git for development and need my private key available
Since the remote is shared, I want to use SSH agent forwarding and keep my private key(s) on my local machine
Config file:
Host mybox
HostName actual.ip.or.name.of.mybox.com
User myusername
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
PowerShell Commands (Run as Administrator)
Start-Service ssh-agent
ssh-add C:\Users\<username>\.ssh\id_rsa # private key to add
ssh-add -L # list keys added
Set-Service ssh-agent -StartupType Automatic # optional

GitLab does not work with key loaded in Pageant?

I keep most of my personal projects on BitBucket by Atlassian. As a natural choice, I use SourceTree app (their product) as git GUI client on Windows, and I'm happy with it. For projects where ssh git is available, I prefer ssh over https. SourceTree plays very well with projects hosted on BitBucket. Although it offers both of ssh agents: OpenSSH or PuTTY, its default selection is PuTTY/Plink (perhaps because PuTTY is more Windows-familiar).
Recently my establishment requested to host some projects on its own server. At first look it's a git server using GitLab opensource. I can use SourceTree with project hosted here using https just fine, however when it comes to ssh, the only choice of SSH agent is OpenSSH. The only key pair it would use (unless specified in config) is ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa (located in %USERPROFILE%\.ssh\
I've tried to:
Load ~/.ssh/id_rsa into PuTTY Key Generator
Convert it to PuTTY format (.ppk) file
Load the .ppk into Pageant (PuTTY authentication agent).
Despite the key being loaded and kept in the memory by Pageant, the connection with the server failed all the time, e.g. git: fatal: Could not read from remote repository. The only way to make it work is to start ssh-agent and ssh-add (go with OpenSSH).
Since I have Pageant running usually in the background, I find it more convenient to use (e.g. the keyphrase to open the private key is long/complex, and I don't remember it, and it can be copy-pasted from KeePass, while in the case of OpenSSH, cmd console does not allow me to paste it, too bad).
Is there anyway to make the ssh authentication to GitLab done via PuTTY instead of OpenSSH?
Did you connect to the SSH server using PuTTY before using plink? If not a reason could be that plink is refusing to connect to the server, because the ssh hostkey isn't verified yet. Another reason could be that the SSH server requires ciphers which are not supported by PuTTY. You can only find out if you connect with PuTTY with the same version as plink.
Use TortoiseGitPlink (from TortoiseGit) to circumvent this issue, as it will popup a messagebox asking whether to accept the hostkey or not.

Git SSH won't connect on custom port

I'm running on a Windows 7 machine with msysgit, git Bash, tortoisegit and posh-git all installed.
Our company has a git server that previously ran on https. Then, for a time it had both https and ssh. Now it has only ssh. Everything ran without issues on https.
I generated and installed all my keys without a problem. I can push/pull/whatever via tortoisegit with no problems. However, I can no longer use the command line in either git BASH or powershell + posh-git. I think part of the reason is because we do not use port 22, but a custom port for increased security.
Note that hostname and port number have been changed in the commands below to protect the innocent.
I get the errors below when trying to push/pull, but I'm showing commands just to test the ssh server to show that ssh is the issue (I believe). If I don't specify the port, it finds the server and attempts to connect - but since it defaults to port 22 I get an error as shown below:
C:\gitpath\design [master]> ssh ssh://git#dev.zzz.us
ssh: connect to host dev.zzz.us port 22: Bad file number
If I do specify the port, however, it then cannot find the hostname:
C:\gitpath\design [master]> ssh ssh://git#dev.zzz.us:9092/
ssh.exe": Could not resolve hostname dev.zzz.us:9092/: no address associated with name
I've looked at similar posts and they all pointed to needing the protocol included (ssh://) to prevent this error. As you can see, I'm getting this error even with the protocol in place. I've also tried with and without the ending '/' - same result. Is there something else with the syntax I'm missing?
Identifiers such as ssh://git#dev.zzz.us:9092/ can be used by git to specify
a non-standard port for SSH when configuring remote repositories. However, the
remote identifier must include the path (I prefer to use the absolute path) to
the remote repository, e.g.,
git remote add origin ssh://git#dev.zzz.us:9092/path/to/repo.git
However, to test such a connection using the ssh command, you use the -p
option to specify the TCP port number and then user#hostname:
ssh -p 9092 git#dev.zzz.us
Note: I usually use Git from a Unix system (not from Windows) and the ssh
command is provided by the Openssh package.
Edit: I just checked on a Windows box and see that MSysGit also uses Openssh
so the above commands work; I haven't checked with Powershell but there shouldn't
be any issues running the above commands through the Bash shell.

Eclipse ADT known hosts

I have trouble getting the official Windows ADT 21.1.0 distribution to connect to a git repository. No matter what I tried(details below) it complains about host key not present in the registry and shows me no option to accept the host key. The remote server is running Gitlab and is under my control. There's no problem with connectivity or firewalls.
What I tried so far:
connecting without giving a password, with user git
connecting while giving a password, with another user
adding manually the host key in the known_hosts file that is found in the ssh home directory(Preferences->General->Network Connections->SSH2->SSH2 home).
The message is always:
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 xx:xx:xx...
Connection abandoned.
RSE works without any problems, only egit gives me problems.
You could workaround the problem by not using the ssh protocol with the git server, but instead the git or http protocol.
One reason for the above message can be using a folder called "ssh" instead of ".ssh" (note the dot). Some colleague of mine experienced that, and this can easily happen when using Windows explorer, as it will silently remove the dot, when creating a folder called ".ssh". You have to use the command line instead.

Git and http_proxy (SparkleShare on windows and http_proxy)

I've just successfully built SparkleShare for windows according to guide:
https://github.com/wimh/SparkleShare/wiki
and exported my ssh public key to a server.
The problem is that I can't connect from a client behind a http_proxy to a public server with ssh running on a custom port. I had also problem with cloning any git server. I need to switch git:// protocol to http:// one. Any suggestion? Does anyone have similar experience?
This is a log file:
15:25:13 [SSH] ssh-agent started, PID=4380 Identity added:
C:\Users\MYUSER\AppData\Roaming\sparkleshare\sparkleshare.MYEMAIL.key
(C:\Users\sg0922706\AppData\Roaming\sparkleshare\sparkleshare.MYEMAIL.key)
15:25:34 [Fetcher][C:\Users\MYUSER\Documents\SparkleShare.tmp\share]
Fetchin g folder: ssh://MYGITUSER#MYHOST/MYPATH 15:25:34 [Fetcher]
Disabled host key checking MYHOST 15:25:34 [Cmd] git clone --progress
"ssh://MYGITUSER#MYHOST/MYPATH" "C:\Us
ers\MYUSER\Documents\SparkleShare.tmp\share" 15:25:37 [Git] Exit code
128 15:25:37 [Fetcher] Failed 15:25:37 [Fetcher] Enabled host key
checking for MYHOST
To get SparkleShare to use your proxy you will need to modify the config of the msysgit that is installed as part of SparkleShare. Navigate to C:\Program Files (x86)\SparkleShare\msysgit\etc and edit the gitconfig file in notepad and add the following line under the [http] tag
proxy = http://user:pass#proxyurl:port
modifying the url as required to match your settings. You can then use the "On my own server" option to add the http url of your repository.
I have a work around on this particular problem. I guess that you already successfully connected to your server via a simple SSH client (i.e. PuTTY)? With PuTTY you can easily configure an ssh connection via any kind of proxy (such as HTTP, SOCKS, Telnet, ..)
What you can do now is to specify a local "tunnel" (an SSH port forwarding rule) like this: L22 127.0.01:22 (see attachment). If you are using a ssh command line add the following option: -L 22:127.0.01:22.
So now as soon as your terminal is open and running you'll be able to reach your git server via the server url: ssh://git#127.0.0.1.
If your local port 22 is busy you can define the tunnet on a other port. i.e. if the 44 is not occupied: L44 127.0.0.1:22. The url to use in SparkleShare become ssh://git#127.0.0.1:44.
But it's a work around. I'm looking for a better solution.

Resources