6

So, if i do this:

su -c 'screen -dmS screenname script to run' - user to run as

It won't work. The screen command is working if excecuted from root, so there is no problem there.

If I do:

su - user
screen

I get:

Cannot open your terminal '/dev/pts/0' - please check.

What is wrong?

EDIT: I've been searching around and can't seem to find any good solution to this problem.

I'll be going for the next best thing: running the screens as root.

totokaka
  • 202
  • 2
  • 8

3 Answers3

8

There is a better trick:

su - user
script /dev/null
screen
Victor
  • 371
  • 1
  • 3
  • 9
5

The reason is that when you login, you get a tty which in your case is currently called /dev/pts/0. You are the only one with access to that tty, otherwise other users could mess with your session while you're working. (Root, of course, also has access, because root always has access to everything.)

When you su to someone else, you still keep your own tty - because that's where your stuff will be shown. But now you want the other user you're su-ing to be able to take over your tty and start showing their own stuff in it.

If you trust everybody else on the server, or at least the other user you're suing to, you can make your tty writable for all, or add yourself and that other user to a group and make it writable for that group. Or you could start the screen as yourself and then su from within it instead.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
  • You could also have a look at the multiuser and addacl facilities, maybe sudo to the other user and start screen detached, and then attach to it. – Jenny D Sep 28 '12 at 09:36
  • So it would work if I use sudo insted of su? – totokaka Sep 28 '12 at 09:44
  • Sorry, I miswrote. Sudo is just a way of running things as root or other users without having their passwords, it doesn't alter the tty problem. – Jenny D Sep 28 '12 at 09:53
  • Hmm, do you know a way to bypass the tty problem? chomd o=rw /dev/pts/0 ? – totokaka Sep 28 '12 at 09:57
  • That should do it - provided you trust everybody else who has access to that server. – Jenny D Sep 28 '12 at 10:28
0

You can run your screen this way:

script -q -c "screen -RD" /dev/null

RJS
  • 1,479
  • 9
  • 9