<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>~iany/ SSH</title><link>https://blog.iany.me/tags/ssh/</link><description>Recent content in SSH «~iany/»</description><language>en-US</language><managingEditor>me@iany.me (Ian Yang)</managingEditor><webMaster>me@iany.me (Ian Yang)</webMaster><copyright>CC-BY-SA 4.0</copyright><lastBuildDate>Tue, 09 Feb 2021 20:08:23 +0800</lastBuildDate><atom:link href="https://blog.iany.me/tags/ssh/index.xml" rel="self" type="application/rss+xml"/><item><title>SSH Authentication Using a YubiKey on Windows And the OpenSSH Client</title><link>https://blog.iany.me/2021/02/ssh-authentication-using-a-yubikey-on-windows-and-the-openssh-client/</link><pubDate>Tue, 09 Feb 2021 20:08:23 +0800</pubDate><author>me@iany.me (Ian Yang)</author><guid>https://blog.iany.me/2021/02/ssh-authentication-using-a-yubikey-on-windows-and-the-openssh-client/</guid><description>&lt;p&gt;As mentioned in &lt;a href="https://blog.iany.me/2020/07/yubico-for-windows/"&gt;♯ Yubico for Windows&lt;/a&gt;, I used PuTTY/Plink instead of the OpenSSH client together with YubiKey because the OpenSSH Client does not support the socket file created by GnuPG.&lt;/p&gt;
&lt;p&gt;Plink does not work well in Windows Terminal. The Visual Studio Code &lt;a href="https://code.visualstudio.com/docs/remote/ssh-tutorial"&gt;SSH Remote&lt;/a&gt; does not support Plink as well, because it will pass some command line arguments that are not supported by Plink.&lt;/p&gt;
&lt;p&gt;So I decide to switch back to the OpenSSH client. Fortunately, the utility &lt;a href="https://github.com/benpye/wsl-ssh-pageant"&gt;wsl-ssh-pageant&lt;/a&gt; can create a tunnel between a Windows pipe and the pageant socket, and the OpenSSH client can use the Windows pipe as &lt;code&gt;SSH_AUTH_SOCK&lt;/code&gt;. This article is a tutorial to set up wsl-ssh-pageant.&lt;/p&gt;
&lt;h2 id="enable-putty-support"&gt;Enable PuTTY Support&lt;/h2&gt;
&lt;p&gt;First edit &lt;code&gt;gpg-agent.conf&lt;/code&gt; in folder &lt;code&gt;$(scoop prefix gpg)\home\&lt;/code&gt;, enable PuTTY support&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;enable-putty-support
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Restart gpg agent to reload the config file.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gpg-connect-agent killagent /bye
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="install-openssh-client"&gt;Install OpenSSH Client&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;This section is copied from &lt;a href="https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse"&gt;Installation of OpenSSH For Windows Server | Microsoft Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To install OpenSSH, start Settings then go to Apps &amp;gt; Apps and Features &amp;gt; Manage Optional Features. Or install it using PowerShell:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
# This should return the following output:
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, install the client feature:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# It should return the following output:
Path :
Online : True
RestartNeeded : False
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="set-up-wsl-ssh-pageant"&gt;Set Up wsl-ssh-pageant&lt;/h2&gt;
&lt;p&gt;Install &lt;a href="https://github.com/benpye/wsl-ssh-pageant"&gt;wsl-ssh-pageant&lt;/a&gt; by downloading the binary from the GitHub release or using scoop&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;scoop install wsl-ssh-pageant
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a cmd file &lt;code&gt;winssh-agent.cmd&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-batch"&gt;wsl-ssh-pageant.exe --systray --winssh ssh-pageant
PAUSE
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Double-clicking this file will start the tunnel.&lt;/p&gt;
&lt;p&gt;Add the environment variable to tell OpenSSH client to use the pipe created by &lt;code&gt;wsl-ssh-pageant&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;[Environment]::SetEnvironmentVariable('SSH_AUTH_SOCK', '\\.\pipe\ssh-pageant', 'User')
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The environment variable is only effective in new windows, so start a new terminal window to try that the tunnel works.&lt;/p&gt;
&lt;p&gt;First, start the gpg agent and check that the card reader works:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;gpg --card-status
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now try to authenticate SSH, for example, to GitHub&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ssh git@github.com
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id="auto-start-wsl-ssh-pageant"&gt;Auto Start wsl-ssh-pageant&lt;/h2&gt;
&lt;p&gt;Create a shortcut in Windows Start Menu to auto-start wsl-ssh-pageant on login and allow launch it by searching in the start menu by pressing the Windows key.&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;# Change the path to the cmd file.
$SSHAgentLocation = &amp;quot;X:\Path\to\winssh-agent.cmd&amp;quot;
$SSHAgentShortcut = &amp;quot;$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\SSH Agent.lnk&amp;quot;
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($SSHAgentShortcut)
$Shortcut.TargetPath = $SSHAgentLocation
$Shortcut.WindowStyle = 7
$Shortcut.Save()
mkdir -Fo &amp;quot;$env:APPDATA\Microsoft\Windows\Start Menu\Programs\SSH Agent&amp;quot;
cp -Fo &amp;quot;$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\SSH Agent.lnk&amp;quot; &amp;quot;$env:APPDATA\Microsoft\Windows\Start Menu\Programs\SSH Agent\SSH Agent.lnk&amp;quot;
&lt;/code&gt;&lt;/pre&gt;</description><category domain="https://blog.iany.me/post/">Posts</category><category domain="https://blog.iany.me/tags/ssh/">SSH</category><category domain="https://blog.iany.me/tags/windows/">Windows</category><category domain="https://blog.iany.me/tags/yubikey/">YubiKey</category></item></channel></rss>