using screen in another user with su

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.


Solution 1:

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.

Solution 2:

There is a better trick:

su - user
script /dev/null
screen