Short question:

How do I connect to a local unix socket (~/test.sock) via ssh? This sockets forwards to an actual ssh server. The obvious does not work and I can't find any documentation:

public> ssh /home/username/test.sock
"ssh: Could not resolve hostname: /home/username/test.sock: Name of service not known"

Long Question:

The Problem I try to solve, is to connect from my (public) university server to my (local) PC, which is behind NAT and not visible to public.

The canonical solution is to create a ssh proxy/tunnel to local on public:

local> ssh -NR 2222:localhost:22 public

But this is not possible, as the administration prohibits creating ports. So I have thought about using UNIX socket instead, which works:

local> ssh -NR /home/username/test.sock:localhost:22 public

But now, how can I connect to it with ssh?

3 Answers 3


You should be able to do utilizing socat and ProxyCommand option for ssh. ProxyCommand configures ssh client to use proxy process for communicating with your server. socat establishes two-way communication between STDIN/STDOUT (socat and ssh client) and your UNIX socket.

ssh -o "ProxyCommand socat - UNIX-CLIENT:/home/username/test.sock" foo
  • 1
    Alternatively, you may use: ProxyCommand nc -U /home/username/test.sock if you don't have socat installed.
    – Yeti
    Commented Mar 24, 2023 at 8:25
  • @Yeti not all version of nc support unix sockets. I think only bsd netcat and nmap ncat. But not the busybox or the gnu. Commented Apr 23 at 7:49

I've submitted pull request to make this work, but it haven't been merged yet:


  • Welcome to the site, and thank you for your contribution. You may want to edit your post to include a summary your proposed changes, and how this will solve the OPs problem.
    – AdminBee
    Commented Aug 20, 2020 at 14:18

I stumbled about https://medium.com/@dperny/forwarding-the-docker-socket-over-ssh-e6567cfab160 which talks about socket forwarding would be possible since OpenSSH 6.7.

Given example is:

ssh -nNT -L $(pwd)/docker.sock:/var/run/docker.sock user@someremote

so no need for socat any more.

  • 1
    -1. This is not what the question is about. The linked article is from 2016 and the question here already uses socket forwarding (with -R, socket to port, but still). The OP wants to connect to already existing local socket (local while being on public) instead of to user@someremote. The answer with socat makes this possible, foo there is a dummy address. Your answer connects to user@someremote. Commented May 9, 2020 at 21:02
  • did not see that. Thanks for the explanation Commented May 11, 2020 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .