Introduction
PTY(AKA Pseudoterminal) is used for implementing terminal emulators such as xterm
… It is involved in enabling the interpretation of passed data in the same way a real terminal would interpret the data … This becomes important when sending input to programs(such as su
and sudo
) that normally refuse to read input from pipes.
In Ubuntu(and many other Linux distributions), PTYs(slaves are the ones of interest to you here) are pseudo-devices identified under /dev/pts
... These device files are dynamically created by /dev/ptmx
(the pseudoterminal multiplexor device) upon user login to a virtual terminal and removed after user logout ... The default owner of those device files are the logged-in user and the tty
system group ... This group is used by the write
and the wall
utilities to enable them to write to other people's virtual terminals, but it is not intended to be used directly.
How it's done
The right way
I wouldn't advise changing permissions at all for security reasons and as these are pseudo-device files and you can mess them up ... And it isn't intended to work that way.
The way to communicate is like so:
Ask the other user on /dev/pts/2
(this can be found by the command tty
) to allow receiving messages from you using the mesg
command like so:
mesg y yourusername
Start sending messages to that user like so:
write their_username /dev/pts/2
Or pipe output to them like so:
date | write their_username /dev/pts/2
Or redirect output to them using bash
's process substitution like so:
date >(write their_username /dev/pts/2)
Notice: that the user receiving messages must be logged in through terminal not through the X session only ... i.e. :
$ who
ubuntu :0 2023-01-12 19:48 (:0) <--- Logged-in through X
ubuntu pts/3 2023-01-27 22:50 <--- Logged-in through terminal
The bad way (in response to your request)
For example, I would like to be able to execute this command : date >
/dev/pts/2 Is it possible for the other user to give me the permission
using chmod xxx /dev/pts/2 and what would be the value replacing the
xxx ?
The information below is just for science and not recommended to try at all:
This is still very bad practice, but for the sake of knowledge ...
The virtual terminal is usually owned by the logged-in user and the tty
group(this group is used by utilities like write
and wall
and has some default members like x
and syslog
) ... So, the logged-in user can change the ownership and the permissions of the virtual terminal device file without needing sudo
... Therefore, if the other user runs:
chown user:group /dev/pts/2
keeping their owner user
and changing only the owner group
to the name of the group that you are both members of ... And gives write permission to the group(this is the default so, might not be needed but just in case) like so:
chmod g+w /dev/pts/2
Then you'd be able to redirect output to their terminal e.g. like so:
date > /dev/pts/2
Keep in mind that will, however, grant write permissions to all existing members(and those who might be added to the group meanwhile) of your group and will deny all permission from the original tty
group.
This will also be temporary until the user logs out and then the virtual terminal device file should disappear and new virtual terminal device files should be created with the default right permissions upon subsequent user logins.