Sample Header Ad - 728x90

Pseudo Terminal Error :: "mesg: cannot open /dev/pts/2: Permission denied"

0 votes
1 answer
3580 views
On my Ubuntu 20.04.5 machine, I have a Perl script running under userA's account. The script issues this command: sudo su - userB -c "ssh -l userB 10.0.0.1 ls -tr /some/remote/directory" (i.e., SSH to a remote host as userB, and then list all the files in /some/remote/directory) The command works great... except that I'm seeing an error on the command line: me@ubuntu1$ sudo su - userB -c "ssh -l userB 10.0.0.1 ls -tr /some/remote/directory" mesg: cannot open /dev/pts/2: Permission denied Welcome to 10.0.0.1! You have logged in. file1.txt file2.txt file3.txt me@ubuntu1$ What is that mesg: cannot open /dev/pts/2: Permission denied message??? A little Internet research reveals that: > Entries in /dev/pts are pseudo-terminals (pty for short). Unix kernels > have a generic notion of terminals. A terminal provides a way for > applications to display output and to receive input through a terminal > device. And assuming that I'm only reading through my pseudo-terminal: > If a program opens a terminal for reading, the input from the user is > passed to that program. If multiple programs are reading from the same > terminal, each character is routed independently to one of the > programs; this is not recommended. Normally there is only a single > program actively reading from the terminal at a given time; programs > that try to read from their controlling terminal while they are not in > the foreground are automatically suspended by a SIGTTIN signal. That's interesting... but I'm still befuddled why I'm seeing mesg: cannot open /dev/pts/2: Permission denied. I'm still developing my script and have run it several times; I can't remember if I noticed this error message on the first run. Is it likely that every time my script runs, it tries to access /dev/pts/2 every time, but my code didn't properly close the connection or something? Or might this be related to userA using userB to run the command? Pseudo-terminals wouldn't come into play when accessing another user account, would they? Any insight or feedback is welcome, thank you.
Asked by Pete (105 rep)
Nov 16, 2022, 05:07 PM
Last activity: Sep 8, 2023, 08:55 AM