Ssh multiplexing via port forwarding

multiplexingsshssh-tunnel

I'm trying to create a setup where one could "ssh" to a specific port on localhost and then get forwarded to a remote server and into a shell, without the need to enter credentials (nope, secret key is not an option, unfortunately).

So far I have set up ssh multiplexing, with ControlMaster, so I can start a remote ssh shell without any prompts, from the local shell.

Is there a way to use that socket when new client connects to a specific port on localhost?

I've tried various combinations with -D, -R and -S, with no luck. Is such a setup possible, on either Linux or Mac?

edit:

I don't mind entering localhost credentials at any point, but I'm trying to avoid entering remote credentials for all connections following the initial control connection.


localhost        ---->    localhost:2222             ---->   remote:22
  $ ssh -p 2222             forward to remote                  $ _ :)
                            using an existing 
                            control socket

Best Answer

If you want a basic shell, you could use netcat to create a shell listening on a certain port on remote server, and use Port Forwarding on local ssh to create the tunnels:

On remote:

while true ; do netcat -l -p 15000 -e /bin/bash ; done

On local:

ssh -L 5000:remoteip:15000 user@server
netcat localhost 5000

You will not be able to use some commands (vim behaviour is funny), but it works for most commands. Every time the connection is closed, the loop will spawn a new one.