Overview
In multi-tenant Unix-like operating systems, users sharing the same host can broadcast text directly onto each other’s consoles. The mesg utility governs whether your current shell window accepts or rejects incoming terminal writes initiated via utilities like write and talk. This tutorial dissects how mesg interacts with underlying pseudo-terminal (/dev/pts/*) character device permissions, walks through toggling reception modes, and demonstrates verifying message routing in real time.
Inspecting Active TTY Sessions and Querying mesg Status
Determining the device node backing your current shell session is the first diagnostic step. Executing tty prints the canonical path of the active terminal:
tty
When standard input operates in a non-interactive automation context rather than an attached hardware console or virtual terminal, the command returns not a tty.

To identify the login identity and terminal line tied specifically to the calling session, invoke who am i:
who am i
An empty return value indicates that no interactive controlling TTY has been allocated to the current subshell environment.

The mesg binary regulates whether neighboring users can pipe text straight onto your display through commands such as write or talk. Running mesg without positional arguments queries the existing reception policy:
mesg
⚙️ [Supported Operational Flags]
y : Permits write operations to your terminal device from non-root local accounts.n : Revokes external write privileges, silencing unsolicited incoming messages.-v : Generates descriptive feedback detailing state updates or current configurations.

Restricting Inbound Messages and Auditing Device Node Permissions
To prevent unexpected terminal writes from interrupting interactive workflows, disable incoming communication by passing the n operand:
mesg n
This instruction flips the terminal policy into non-receptive mode, causing third-party write or talk attempts to fail immediately with permission denials.

Verify that the suppression flag took effect across the current shell session by querying mesg again:
mesg
The shell should return is n, confirming that external transmission requests will be dropped.

Under the hood, mesg modifies the permission bits of the active pseudo-terminal character device. Inspect these access privileges directly using ls -l $(tty):
ls -l $(tty)
Executing mesg n clears group and world write bits on the character special file (e.g., changing permissions from crw--w---- to crw-------), thereby leveraging the Linux Virtual File System security model to block writes.

Restoring Write Privileges and Testing Live Inter-Terminal Transmissions
When collaborative peer-to-peer console interaction is required, re-enable broadcast reception using the y argument:
mesg y
This updates your session state to accept inbound communication streams once more.

Confirm that the receiving interface has transitioned back to an open status:
mesg
The output is y signals that the terminal is actively listening for broadcast messages.

Examine the pseudo-terminal device node again with ls -l $(tty) to see the restored permission bits:
ls -l $(tty)
The group write privilege (w) is once again active on the device file (typically owned by the tty system group), permitting authorized local processes to push text into the buffer.

To simulate an authentic message transmission, pipe a diagnostic string directly into write, targeting your current username and terminal identifier:
echo 'Test message via terminal' | write $(whoami) $(tty | cut -d/ -f3-4)
Directing this pipeline to your own allocated PTS device delivers immediate visual validation of the working delivery path.

Automating Terminal Privacy via Shell Startup Scripts
To enforce a quiet, interruption-free terminal policy across all future login sessions, configure the setting within shell profile scripts. First, prepare an isolated workspace:
mkdir -p ~/mesg_test && cd ~/mesg_test

Append the suppression directive to an experimental shell configuration profile:
echo 'mesg n' >> ~/.bashrc_test_profile

Inspect the configuration file with grep to ensure the entry was written accurately:
grep 'mesg' ~/.bashrc_test_profile
The presence of mesg n confirms that the desired initialization routine is properly defined.

Launch an isolated Bash instance pointing to the test startup configuration to verify execution:
bash --rcfile ~/.bashrc_test_profile -c 'mesg'
In headless or non-interactive environments lacking an attached TTY descriptor, mesg cleanly handles the absence of an interactive terminal according to standard shell semantics.

Once verification is complete, clean up the temporary workspace and sample profile:
rm -rf ~/mesg_test ~/.bashrc_test_profile

Understanding how mesg controls terminal node privileges allows Linux administrators and developers to effectively safeguard against unwanted terminal disruptions while retaining the ability to collaborate in shared multi-user server environments.