2

On my linux box, when using screen I can open, read and write to a pseudo terminal with screen. After closing it (C-a k y) I can't connect to it again, without restarting socat, which provides the pseudo terminal.

Just after starting socat things look like this:

 /home/kidmose $ fuser /dev/pts/9
/dev/pts/9:          20960
 /home/kidmose $ lsof /dev/pts/9
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
socat   20960 kidmose    5u   CHR  136,9      0t0   12 /dev/pts/9

and I can write and read as expected:

 /home/kidmose $ echo "uname -a" > /dev/pts/9 && cat /dev/pts/9 
uname -a
Linux egki-laptop-linuxmint 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Starting screen also works once (I can write and read the expected output):

 /home/kidmose $ screen /dev/pts/9
uname -a # My input
Linux egki-laptop-linuxmint 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux # Response
(C-a k y) # I kill the window and screen terminates ([screen is terminating])

Now I can no longer connect with screen nor simply write. Screen immediately exits with [screen is terminating] and I get the following error when trying to write:

 /home/kidmose $ echo "uname -a" > /dev/pts/9 && cat /dev/pts/9 
bash: /dev/pts/9: Device or resource busy

Some info:

 /home/kidmose $ fuser /dev/pts/9
/dev/pts/9:          20960
 /home/kidmose $ lsof /dev/pts/9
COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
socat   20960 kidmose    5u   CHR  136,9te      0t0   12 /dev/pts/9
 /home/kidmose $ 

Any ideas on why it is 'busy' / unavailable?

I've noticed the 'te' appears in the lsof output. Any explanation for that?

My final goal is to have like a virtual terminal on a remote device. Due to NAT etc. I need the remote device to call in to the server, where the the virtual terminal will be.

Edit: As lemonsqueeze put it in his comment:

[A: sh -> socat] --> [B: socat -> pty -> screen]
   Machine A     TCP        Machine B
  • Where exactly does socat come into the picture ? – lemonsqueeze Oct 11 '14 at 7:06
  • I run socat with a TCP server and the pseudo terminal(pty), so I can run a shell on another machine and redirect IO from the shell, via TCP to the pty. My goal is to achive a remote shell, but due to NAT i need the "SSH Server" to initiate the connection. Does this make sense? – kidmose Oct 11 '14 at 13:38
  • 1
    Almost. So you have two machines A and B. You want a remote shell on A from B but you can't because A is NAT'ed. So you have A connect to B instead with socat and do some plumbing: [A: sh -> socat] -> [B: socat -> pty -> screen]. Something like this ? – lemonsqueeze Oct 11 '14 at 14:11
  • Yup. Nice way of formatting it :) – kidmose Oct 12 '14 at 10:08
  • Ok, what command do you use for socat on B ? – lemonsqueeze Oct 12 '14 at 10:50
2

Suggestion: In this situation I'd go with a Reverse SSH connection:

Instead of your machine doing an ssh, the server machine does an ssh and through port forwarding makes sure that you can ssh back to server machine.

But it's certainly not as fun as building it yourself with socat. I'd still recommend getting to the bottom of this pty issue, it's a good way to learn.

  • Seems like the exact thing I was trying to achieve. Thanks! – kidmose Oct 13 '14 at 5:52

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.