Inappropriate ioctl for device when trying to SSH

I am trying to use multiple SSH servers and am trying to get the output of sudo -l

each server.

Below script I am executing

#!/bin/bash
serverlist="/tmp/servers"

while IFS=, read -r server netgroup username user
do
        ssh -tt -q root@$server sudo -U $username -l < /dev/null
done < "$serverlist"

      

I found that a parameter -tt

in this script is causing this error. Any thought on this?

Also I noticed that I don't see this error when I execute below command for only 1 server.

ssh -tt -q root@myserver sudo -U cham01 -l

Below is the complete error message I am getting: tcgetattr: Inappropriate ioctl for device

+3


source to share


2 answers


tcgetattr: Inappropriate ioctl for device

usually means that some program tried to perform a terminal control operation, but its standard I / O streams were not connected to the terminal. (I know this because tcgetattr

is the name of a C library function that performs terminal control operations.)

Now the whole option -tt

for is ssh

to ensure that the program running on the remote host is connected to the terminal and the stty

printout speed 38400 baud; line = 0; -brkint -imaxbel

shows that it was. This is what I get when I run these commands with my servers:

$ ssh myserver stty < /dev/null
stty: 'standard input': Inappropriate ioctl for device

$ ssh -tt myserver stty < /dev/null
speed 38400 baud; line = 0;
-brkint -imaxbel
Connection to myserver closed.

      



But you get

$ ssh -tt yourserver stty < /dev/null
tcsetattr: Inappropriate ioctl for device
speed 38400 baud; line = 0;
-brkint -imaxbel

      

The error tcsetattr

does not come from stty

. At first something tried to do something terminal related and failed and then stty

succeeded. This indicates a bug in shell startup scripts that do something inappropriate when launched "non-interactively", causing you to get this error even if you are using terminal-connected commands. I can't help you, but maybe this old answer about a similar problem offers some clues.

+5


source


In this answer, I am not suggesting a solution (I don’t know where the error is coming from), but instead, I am going to offer a powerful tool to find it!

To understand where the problem is from, you can use the command strace

:

strace ssh -tt -q root@myserver sudo -U cham01 -l < /dev/null 

      

Of course, you will understand which one is the system call causing the error. The shell will ask for all system calls and at some point near the end you will see something like:



....
ioctl(3, SNDCTL_TMR_START or TCSETS, {B0 -opost -isig -icanon -echo ...}) = -1 ENOTTY (Inappropriate ioctl for device)
....

      

Here you can find examples of how to use it.

Recommendation: there ioctl(...)

must be a system call open(...)

for the same device before the system call . Go to the device header file and try looking at some other command you can pass. The problem must be an unrecognized command (due to possibly an older version of the device driver being used). This is just a suggestion.

+1


source







All Articles