Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

There is daemon in my system, it runs inside of a screen instance and all that is done from an unpriveleged user. I’ve added myself to special sudo group allowing me to run screen from this user, but when I try to use it, e.g.

sudo -u that_user -H /usr/bin/screen -R

I get the subject of this post.

Digging around I found that this message means that screen cannot grab or do output to the pty I actually use when calling it. Common answer to this is to chmod my /dev/pts/N to be rw for the others, but I remember I somehow managed to avoid this earlier. Maybe I missed to save some environment for sudo?

In particular I’m trying to connect to rtorrent daemon running in screen from an ordinary user via sudo, OS is Gentoo amd64. Here is how screen is called from the rc-script:

    start-stop-daemon \
        --start \
        --make-pidfile \
        --pidfile /var/run/rtorrentd.pid \
        --background \
        --user $USER \
        --env HOME="${PWHOME:-/home/$USER}" \
        --name rtorrent \
        --exec /usr/bin/screen -- -D -m -S rtorrentd /usr/bin/rtorrent

Finally worked the actual solution out:

alias rtorrent="urxvt -hold -e /bin/bash -c \"chmod o+rw \\\`tty\\\` && sudo -u rtorrent -H screen -r rtorrentd\""
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Since you are running screen as the special user, the special user needs access to your pty. The only way to accomplish this is to change the permissions on the device.

A better approach is to use screen's multiuser feature, which allow users to connect to another user's screen session without using sudo. This requires setting the screen binary setuid root:

sudo chmod u+s /usr/bin/screen

Then create a new screen session, giving the socket a meaningful name:

screen -S torrent

Inside this screen session, enable multiuser mode and authorise the other users:

^A: multiuser on
^A: acladd tijagi

You should then be able to attach the screen session as yourself:

screen -x that_user/torrent
share|improve this answer
    
Thanks for the reply, but it doesn’t work for me for some reason. Here is the output: pastie.org/pastes/6046281/text But I’m afraid of using screen with root setuid anyway, so I’m thinking about to run screen for rtorrent in a special urxvt window which will change its permissions on the fly. –  tijagi Feb 4 '13 at 20:12
    
@tijagi Did you start a new named screen session with screen -S rtorrentd? –  mgorven Feb 4 '13 at 20:47
    
Look at the my first post, I’ve expanded it. –  tijagi Feb 4 '13 at 21:07
    
@tijagi That all looks fine, I'm not sure why it's not working. –  mgorven Feb 5 '13 at 0:39
    
Is it possible to enable this via .screenrc? –  earthmeLon Apr 12 '13 at 18:23
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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