{"id":511,"date":"2015-07-04T19:10:39","date_gmt":"2015-07-04T23:10:39","guid":{"rendered":"http:\/\/pmcgovern.ca\/wp\/?p=511"},"modified":"2021-12-12T12:40:25","modified_gmt":"2021-12-12T17:40:25","slug":"git-git_ssh-and-ssh","status":"publish","type":"post","link":"https:\/\/pmcgovern.ca\/wp\/?p=511","title":{"rendered":"Git, GIT_SSH, and SSH"},"content":{"rendered":"<p>As part of a project at work, a web application running in Tomcat must periodically pull files form Git. No, it&#8217;s not Jenkins. Usually it work a treat but getting it all working on Windows proved to be tricky, and I post the solution here in hopes of saving someone&#8217;s mental health.<\/p>\n<p>Tomcat was running under a service account, user svcacct. In order to present the right identity and host keys, I wrote a simple wrapper to execute ssh with specific keys.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">ssh -o PreferredAuthentications=publickey -o IdentityFile=C:\\Users\\svcacct\\.ssh\\service_acct_pk -o UserKnownHostsFile=C:\\Users\\scvacct\\.ssh\\known_hosts %*\n<\/pre>\n<p>For Git to use this wrapper, the <strong>GIT_SSH<\/strong> environment variable must be set to point to it. Also, the host key was added manually to known_hosts. Tomcat had to be restarted for the new environment variable to take effect.<\/p>\n<p>But it didn&#8217;t work. Git was coughing this into the logs:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">fatal: protocol error: bad line length character:\nc:\n<\/pre>\n<p>After much wailing and gnashing of teeth, and setting <strong>GIT_TRACE<\/strong> to 1, the problem was determined to be caused by Windows echoing the full path the the ssh executable. Git was trying to parse the output of ls-remote and gagging on the &#8220;C:\\Program Files\\&#8221; prefix.<\/p>\n<p>Turning off the echo in the batch file did the trick:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\">@echo off\nssh -o PreferredAuthentications=publickey -o IdentityFile=C:\\Users\\wpsadmin\\.ssh\\id_rsa-transformation_svc -o UserKnownHostsFile=C:\\Users\\wpsadmin\\.ssh\\known_hosts %*\n<\/pre>\n<p>Lessons learned: <strong>GIT_TRACE<\/strong> is your friend, and we&#8217;re <em>still<\/em> farting around with batch files in 2015.<\/p>\n<p>More info <a href=\"http:\/\/philippe.bruhat.net\/stuff\/git-fractals\/\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As part of a project at work, a web application running in Tomcat must periodically pull files form Git. No, it&#8217;s not Jenkins. Usually it work a treat but getting it all working on Windows proved to be tricky, and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":513,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=511"}],"version-history":[{"count":4,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":881,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/posts\/511\/revisions\/881"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=\/wp\/v2\/media\/513"}],"wp:attachment":[{"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pmcgovern.ca\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}