title: Piping file contents to remote file over SSH
body: <p>I am trying to share an SSH public key with a remote server using Powershell. Typically, in Linux environments, using Bash, I would use <code>cat</code> and a pipe to append the contents of the file, like so:</p>
  
  <pre><code>cat ~/.ssh/id_rsa.pub | ssh user@machine 'cat &gt;&gt; ~/.ssh/authorized_keys'
  </code></pre>
  
  <p>However, I am communicating between Windows 10 hosts using the SSH feature in Windows 10, so do not have access to GNU utilities.</p>
  
  <p>Instead, I am trying to use Powershell. I currently have the following Powershell code:</p>
  
  <pre><code>Get-Content ~\.ssh\id_ed25519.pub | ssh user@machine "'$_' | Out-File -FilePath ~\.ssh\authorized_keys -Append"
  </code></pre>
  
  <p>This runs without error but the file on the remote machine is empty. How would I go about appending my public key to the <code>authorized_keys</code> file on the remote machine?</p>
  
  <p>I may be approaching this problem from the wrong direction; most of my shell scripting experience is in Bash on Linux. If there is a cleaner Powershell solution, I would love feedback!</p>
  
  <p><strong>CLARIFICATION</strong>: I am using PowerShell as the default shell on my remote Windows host.</p>