How can I establish a reverse ssh tunnel with my ./ssh/config file?

I'm trying to reproduce this command

ssh -R 55555:localhost:22 user@host

in my .ssh/config file so that when I type ssh host I'll ssh to the host as user and with a reverse tunnel. The commands accepted by the config file are more verbose counterparts to the command line flags. Based on the ssh manpage and the manpage for ssh_config, it seems like the corresponding setting is BindAddress.

In my .ssh/config file I have:

Host host
     Hostname host
     User user
     BindAddress 55555:localhost:22

This, and slight variations of, result in a connection refused when I try

ssh localhost -p 55555

once logged in on the host. The same works fine if I explicitly give the command at the top when first sshing to the host. My config file does work without the reverse tunnel command; ssh host logs me into host as user.

1 Answer 1


BindAddress is not the option you're after. From man ssh_config:

         Use the specified address on the local machine as the source
         address of the connection.  Only useful on systems with more than
         one address.

The configuration file equivalent of -R is RemoteForward:

         Specifies that a TCP port on the remote machine be forwarded over
         the secure channel to the specified host and port from the local
         machine.  The first argument must be [bind_address:]port and the
         second argument must be host:hostport. [...]

With this information the command line

ssh -R 55555:localhost:22 user@host

translates into the following .ssh/config syntax:

Host host
HostName host
User user
RemoteForward 55555 localhost:22
  • 1
    This question should be the poster child for the stackexchange Q&A format.
    – nick fox
    Commented Jun 1, 2022 at 18:45

You must log in to answer this question.

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