diff --git a/.ci/setup_ssh.sh b/.ci/setup_ssh.sh
index 40c0c5c1ef96d9633aac885f0ba0bba4c1168ca3..9c07270b15dc173ee0001d926036d70952e97990 100644
--- a/.ci/setup_ssh.sh
+++ b/.ci/setup_ssh.sh
@@ -21,6 +21,22 @@ set -e
 
 if [[ -f /.dockerenv ]]; then
 
+ # We have to use different host names to connect
+ # to the docker daemon host on mac as opposed
+ # to on linux.
+ #
+ # On linux (assuming the docker job is running
+ # with --net=host), we can connect via
+ # username@localhost.
+ #
+ # On mac, we have to connect via
+ # username@host.docker.internal
+ if [[ "$CI_RUNNER_TAGS" == *"macOS"* ]]; then
+  if [[ "$FSL_HOST" == *"@localhost" ]]; then
+   FSL_HOST=${FSL_HOST/localhost/host.docker.internal}
+  fi
+ fi
+
  apt-get update -y                           || yum -y check-update                     || true;
  apt-get install -y openssh-client rsync git || yum install -y openssh-client rsync git || true;