3

I would like to connect to a remote machine, ideally over SSH, and then pull the commands from there.

To be precise, I would like make a remote machine connect to my local machine, where I would have an interactive console, send commands and see the output.
Functionally it would be similar to Windows Remote Assistant or what's the name.

I can imagine I would implement a HTTP server that would have a GUI, and on request, it would keep the connection forever and send any line that I type to the GUI; and receive everything the other side sends as its output. I would only have to take care of the HTTP headers. However, that's not too elegant.

Is there some such ready-made solution? Or perhaps using nc or some tool that would connect the TTY with a listening port?

Ondra Žižka
  • 879
  • 9
  • 16

3 Answers3

5

If you run:

socat "unix-listen:$HOME/.shell-access,mode=600,fork" \
      "exec:$SHELL,pty,stderr,setsid,ctty"

That allows you to do for instance:

socat -,raw,echo=0 "unix:$HOME/.shell-access"

locally, to connect and interact with that shell.

Then you can remote-port-forward it over ssh with:

ssh -R "/path/to/socket/on/host:$HOME/.shell-access" user@host

(assumes a relatively recent version of openssh (both client and server)).

And then user on host can interact with that shell by doing that

socat -,raw,echo=0 "unix:/path/to/socket/on/host"

Instead of running $SHELL, you could run screen -xRS some-screen-session to attach a given screen session so several people can see the same screen session.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
2

With traditional netcat.

server:

$ nc.traditional  -lvp 1234 -e /bin/sh

client:

$ nc -nv <ip> 1234

You can also forward the port via ssh.

Ipor Sircer
  • 14,376
  • 1
  • 27
  • 34
  • 1
    That means exposing a shell running as you to anyone, so lets anyone who can connect to ip:1234 run any command as you on your machine without authentication. – Stéphane Chazelas Mar 20 '18 at 15:28
0

I would like make a remote machine connect to my local machine, where I would have an interactive console

Create a listen on your locale machine:

socat file:`tty`,raw,echo=0 tcp-listen:PORT

Type the following command on the remote machine:

socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:YOUR_IP_ADDRESSE:PORT
GAD3R
  • 63,407
  • 31
  • 131
  • 192