title: Cannot ssh to remote hosts on any port other than 22 from macOS using built-in ssh client
body: <p>I recently switched the ssh listen port on my server running Dropbear from 22 to a random one to prevent the system log from being flooded by someone brute-forcing.</p>
  <p>Everything is fine and I am able to connect to the server from the wan side using termux(an
  Android terminal emulator that you can install packages).</p>
  <p>Until when I try using my MacBook to ssh into the server(under the same network with my phone, was previously able to ssh into the server when dropbear was listening on 22). The connection immediately drops and ssh throws this at me:</p>
  <pre><code>kex_exchange_identification: write: Broken pipe
  </code></pre>
  <p>The verbose output does not really show anything helpful(and cut really abruptly may I add):</p>
  <pre><code>OpenSSH_8.1p1, LibreSSL 2.7.3
  debug1: Reading configuration data /Users/my_username/.ssh/config
  debug1: Reading configuration data /etc/ssh/ssh_config
  debug1: /etc/ssh/ssh_config line 47: Applying options for *
  debug1: Connecting to remote.yhaoquan.top port 2123.
  debug1: Connection established.
  debug1: identity file /Users/my_username/.ssh/id_rsa type 0
  debug1: identity file /Users/my_username/.ssh/id_rsa-cert type -1
  debug1: identity file /Users/my_username/.ssh/id_dsa type -1
  debug1: identity file /Users/my_username/.ssh/id_dsa-cert type -1
  debug1: identity file /Users/my_username/.ssh/id_ecdsa type -1
  debug1: identity file /Users/my_username/.ssh/id_ecdsa-cert type -1
  debug1: identity file /Users/my_username/.ssh/id_ed25519 type -1
  debug1: identity file /Users/my_username/.ssh/id_ed25519-cert type -1
  debug1: identity file /Users/my_username/.ssh/id_xmss type -1
  debug1: identity file /Users/my_username/.ssh/id_xmss-cert type -1
  kex_exchange_identification: write: Broken pipe
  </code></pre>
  <p>Telnetting to port 2123 shows that I actually successfully made the connection to the server:</p>
  <pre><code>&gt;telnet {hostname} 2123
  Trying {host IP address}...
  Connected to {hostname}
  Escape character is '^]'.
  SSH-2.0-dropbear
  |
  
  ��]J044��d����curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,kexguess2@matt.ucc.asn.aursa-sha2-256,ssh-rsa3chacha20-poly1305@openssh.com,aes128-ctr,aes256-ctr3chacha20-poly1305@openssh.com,aes128-ctr,aes256-ctrhmac-sha1,hmac-sha2-256hmac-sha1,hmac-sha2-256nonenoneM�'�Rf
  </code></pre>
  <p>When I change the port back to 22 on my server, everything works again.</p>
  <p>Does anyone know where the problem might be or what way should I go about diagnosing the problem?
  Thanks in advance :)</p>
  <p><strong>EDIT 1:</strong>
  For those of you who are experiencing the same issue, a <em><strong>temporary</strong></em> solution would be using <code>OpenSSH</code>. The easiest way (that makes this a <strong>drop-in solution</strong>) to do this is by using <code>Homebrew</code>:</p>
  <pre class="lang-sh prettyprint-override"><code>brew install openssh
  </code></pre>
  <p>This command will change the ssh client you use from <code>/usr/bin/ssh</code> to an alias placed at <code>/usr/local/bin/ssh</code> points to the <code>OpenSSH</code> you just installed using brew, which the symptom doesn't seem to appear on.</p>
  <p>This does <strong>not</strong> solve the problem that this post is about. I am still looking for a solution for it.</p>