Linux command of the day, 11 of 31 - mesg

By Gavin Davies on 10 August 2020

Page image
I’m looking briefly at a Linux command every day for a month. Today: mesg

I’m looking briefly at a Linux command every day for a month

Yesterday, digging into who led me to explore that mysterious + character :

$ who -a
LOGIN      tty1         2020-08-09 18:38               501 id=tty1
pi       + pts/0        2020-08-12 06:35   .         30980 (192.168.1.159)
pi       - pts/1        2020-08-12 06:42 00:04       31292 (192.168.1.159)
  • The + is the user pi‘s mesg status, i.e. whether the current user can write to that user’s tty. I have commaands mesg and tty to quickly look up:

For the user in pts/1 I run the following:

$ mesg
is y
$ tty
/dev/pts/1
$ OK let's turn mesg off
$ mesg n

Let’s look at that change:

$ who -aH --lookup | fgrep "pts/1" 
pi       - pts/1        2020-08-12 06:42   .         31292 (192.168.1.159)

I tried to message the pi on pts/1 and get:

$ write  pi pts/1
write: pi has messages disabled on pts/1

So, mesg can be set to on or off, meaning you can refuse messages. What about if you were an admin and wanted to break through that though? Well, one way to do that would be wall, which we’ll look at tomorrow!