Shared Terminal: Two People Typing in One Linux Terminal
In this article
Yes, this tool lets two people type in the same Linux terminal at the same time. It is called a terminal multiplexer with shared sessions, and the most common implementations are tmux and screen. These tools allow multiple users to attach to the same terminal session over SSH, so each keystroke from either user appears in the same output, and both can type simultaneously.
What Exactly Is a Shared Terminal?
A normal Linux terminal is a single process connected to a single user's keyboard and screen. When you run tmux or screen, you create a session that runs independently of any particular terminal window. That session can have multiple windows and panes, and each one is a pseudo-terminal (pty) that can be attached to by more than one client at once.
When two users attach to the same session, they both see the same screen content in real time. If one user types ls, the other user sees the characters appear and the output. Both can type at the same time, and the input is merged into the same terminal stream. This is different from screen-sharing tools like VNC or Zoom, because here both users have full keyboard control and the terminal is the only thing shared.
How to Set Up a Shared Terminal with tmux
The most popular tool for this today is tmux. Here is the typical workflow:
- Install tmux on the machine where the terminal session will run (usually a server). On Debian/Ubuntu:
sudo apt install tmux. On RHEL/CentOS:sudo yum install tmux. - User A creates a new named session:
tmux new -s shared - User B (or User A) needs to connect to the same machine via SSH. Then User B attaches to the same session:
tmux attach -t shared - Both users now see the same terminal and can type. To leave the session without killing it, press
Ctrl-bthend(detach).
For two people on different machines, both must SSH into the same host. If they are on the same machine but different local users, the second user may need to adjust permissions so they can access the tmux socket (see the section on permissions below).
How Does It Actually Work Under the Hood?
Terminal multiplexers create a server process that manages the session. Each session has a control terminal (pty) that runs the shell (like bash or zsh). When a client attaches, it connects to that pty and sends input and receives output. Multiple clients can attach to the same pty because the multiplexer multiplexes the input streams and broadcasts the output to all attached clients.
When two users type simultaneously, the multiplexer interleaves the keystrokes. If User A types echo and User B types hello at the same time, the terminal may receive echhello or some other combination. The result depends on timing and the terminal's line discipline. This is not a bug; it is the nature of shared input. For most collaborative work, users coordinate by taking turns or using separate panes.
Using Screen as an Alternative
The older screen tool also supports multiuser mode. The setup is slightly different:
- User A starts a screen session:
screen -S shared - User A enables multiuser mode:
Ctrl-a :multiuser on - User A adds User B:
Ctrl-a :acladd username - User B attaches:
screen -x shared
Screen requires explicit ACL configuration, whereas tmux is more permissive by default (any user with access to the socket can attach). For most modern use, tmux is simpler and more feature-rich.
Common Problems and Solutions
- Permission denied when attaching: In tmux, the session socket is owned by the user who created it. If User B is a different local user, they cannot attach. Solutions: use a shared Unix group and set the socket permissions, or use
tmux -S /tmp/sharedwith a world-writable socket (not recommended for security). - Both users see a frozen screen: This often happens when one user detaches incorrectly or the session is killed. Check with
tmux lsto see if the session still exists. - Keystrokes get garbled: If both type at the same time, the input interleaves. Use a coordination tool like
tmate(a tmux fork that shares a read-only view) or simply take turns. - SSH connection drops: The session persists because it runs on the server, not on the client. Reconnect with
tmux attachto get back to the same state.
How to Choose Between tmux and screen
For new projects, tmux is the better choice for most people. It has a more intuitive configuration, better split-pane support, and a larger community. screen is older and may be pre-installed on some minimal systems, making it handy when you cannot install new packages. If you need read-only sharing for a spectator, tmux has a read-only option (via set -g remain-on-exit or using tmate).
Security and Safety Considerations
Sharing a terminal means sharing full control of that shell. Anyone attached can run any command as the user who owns the session. Therefore:
- Never share a session as root unless absolutely necessary.
- Use SSH keys and a dedicated user account for collaboration.
- Be aware that all commands and output are visible to all attached users.
- If you need to share only a specific command or a read-only view, consider using
tmateor a web-based terminal sharing service (like tmate.io), but be cautious about sending sensitive data over third-party services.
Frequently Asked Questions
Can two people type at the exact same time in a shared terminal?
Yes, technically both can send keystrokes simultaneously, but the terminal will interleave them in an unpredictable order. For practical purposes, users usually coordinate to avoid confusion.
Does the shared terminal work over the internet?
Yes, as long as both users can SSH to the same server. The terminal session runs on that server, so latency affects keystrokes but not the sharing itself.
What is the difference between tmux and screen for sharing?
tmux is more modern, easier to configure, and handles multiple windows/panes better. screen requires ACL setup and is more basic, but it is often pre-installed.
Can I share a terminal with someone who doesn't have an account on the server?
No, both users need a user account on the machine where the session runs, because they must SSH in. There are third-party services that create temporary shared sessions, but they have their own security risks.
Is there a way to give someone read-only access to a terminal?
Yes, tmux has a read-only option (set with set -g mode-keys vi is not it; you can use tmux attach -r to attach read-only). Alternatively, tools like tmate provide a read-only URL.
What happens if the SSH connection drops for one user?
The session continues on the server. The other user stays attached. The disconnected user can simply SSH back and reattach to the same session.