2

If I am logged in to a remote server, and someone else is logged in to the same server, isn't there some way via the command line to let them "look over my shoulder"?

Of course I could copy and paste my terminal scrollback buffer at intervals and dump it in a file in /tmp, and they could cat that file...that is close to what I'm talking about, though it wouldn't have color.

This is very different from the typical meaning of "screen sharing" because it wouldn't involve any additional network traffic at all—just local resources. (You're both already logged in.)

I have had scores of cases in just a few months where this would have been extremely useful.

Is this possible? How can I do it?

  • @ilkkachu, if you want to do a short writeup on how to use "screen" to accomplish this, I would accept that answer. It doesn't look like "screen" was designed for this use, so the manual is a little tricky to sift through to learn to do the above. – Wildcard Aug 14 '16 at 3:31
  • 1
    I am also looking for the same thing. It does not look like you found you answer here. Have you found any so far? I might want to give conspy a try. It is like a vnc for the cli. – Sean Lee Jul 10 '17 at 16:08
  • @SeanLee, see my self-answer below. – Wildcard Sep 21 '17 at 0:44
4

Many people have suggested screen. Screen is somewhat old, and pretty bad. I suggest tmux.

To create a session just run tmux new -s <name>

Then, to have another person attach to that session, all they have to do is run tmux a -t <name>, making sure to keep the name the same.

Leaving a session can be done by hitting Ctrl-b then d.

Note, this all must be done on the same server / machine.

3

I just came across this option in man script:

-f      Flush output after each write. This is nice for telecooperation:
        One person does ‘mkfifo foo; script -f foo’ and another can
        supervise real-time what is being done using ‘cat foo’.

I haven't played with this yet, but it looks like exactly what I was looking for. Playing with it could establish whether color, etc., is conveyed as well.

  • 1
    Great find! After testing this a bit, one can follow what is happening using less +F foo. Doing so seems to provide a more real-time method than using cat foo. – Timothy Martin Sep 21 '17 at 1:07
1

You can use tee to pipe your output to the terminal of the other person if you know what terminal she is using.

You can use the w command to find out the terminal:

user4@myubuntu:~$ w
 16:41:36 up 13 min,  4 users,  load average: 0.55, 0.60, 0.46
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
user1    :0       :0               16:28   ?xdm?   6:28   0.03s gdm-session-worker [pam/gdm-password]
user2    pts/1    :0               16:38    2:46   0.04s  0.04s bash
user3    pts/7    :0               16:38    1:32   0.09s  0.09s bash
user4    pts/8    :0               16:41    4.00s  0.05s  0.00s w

I'm user4 on terminal pts/8. If I want to send my output to user2 on terminal pts/1, then I use the following command to start a new shell:

$ bash | tee /dev/pts/1

Then all the output of my subsequent commands (not input though) will be copied to the terminal of user2. If you are done, just hit Ctrl-D to terminate the shell.

If you only want to send a message or some text to the other user, you can use the write command:

$ write <username>
hello, are you there ? 
Ctrl-d
1

There is the command screen. I think this is exactly what you are looking for. https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

The important info for you is, that more than one user can attach to the same screen

  • I upvote this. tmux or screen can help you share a session with your mate. tmux new session_name will create a new shared session. Your mate just has to tmux at session_name to attach, and you both can co-work to see each other action – cuongnv23 Aug 13 '16 at 8:05
  • 1
    You might want to add some info on how to do it with screen, even the linked page doesn't seem to have anything on multiuser use. – ilkkachu Aug 13 '16 at 11:13
  • I agree with @ilkkachu; links should not contain the entire content of the answer. Without the link, this doesn't really answer the question—and even on the linked page there is no mention of multi-user use. – Wildcard Aug 14 '16 at 3:29
  • 1
    @Wildcard you can see my comment for tmux – cuongnv23 Aug 14 '16 at 7:36
0

Okay, sharing a screen with screen is possible, but hairier than I thought.

  1. It requires screen to be setuid to root, so it can access the sockets of other users. (One might think this could be made to work with just setgid, but I didn't check if screen can be compiled that way.)
  2. The documentation for the multiuser commands is a bit on the light side, which means that configuring it isn't that simple. Also, while you can set ACLs for other users, there doesn't seem to exist an option for printing the current ACLs.

That said, I was able to get it to work, for some values of "work".

First, make sure it has enough privilege, and fix the permissions on /var/run/screen:

chmod u+s /usr/bin/screen
chmod 755 /var/run/screen

Then, bundle some configuration commands in a file:

$ cat shared.screen.rc
multiuser on
aclumask ?-wx
aclumask ??-wx
addacl foo
aclchg foo -x ?
aclchg foo +x detach,help,next,prev,windows,info,select

multiuser enables multiuser mode, aclumask limits the default access for all users, then addacl allows (all) access to user foo. The aclchg commands remove execute (-x) access to all commands (?), and we then allow some benign commands again.

Then, then running screen -c shared.screen.rc, creates a screen the user foo can attach to:

foo$ screen -ls bar/
There is a suitable screen on:
        18839.pts-2.test        (08/21/16 22:09:07)     (Multi, detached)
foo$ screen -r bar/

Writing to the screen and using most commands result in an error. However, copy mode seems to work. Also, starting screen with screen -rd bar/ as the non-owning user kicks the owning user out, even though you'd imagine that shouldn't be possible. screen -RRD works too, and logouts the original user. Even though you can disallow pow_detach and detach (which should be fun for the second user), it doesn't seem to affect this. Amusing.

Of course, if you don't mind, and are happy to let other users mess with your screen, using multiuser on and addacl foo should be enough. Not that I'm saying you should.

0

I think wemux and tmux are what you are looking for.

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.