Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pseudo tty with ssh results in warning

Tags:

c++

ssh

I am using ssh from my application and must pass "-t -t" to ssh in order for it to work correctly. Otherwise, the stdin of my application is interfered with by the call to ssh. Forcing a pseudo terminal to ssh via the -t -t avoids this issue, but instead results in the following obscure error message coming back from ssh, although the application seems to work correctly otherwise:

tcgetattr: Inappropriate ioctl for device

I'd like to get rid of this message to keep it from happening instead of just supressing it, but am not sure why it is coming and what I should do to prevent it. I only get the message when -t -t are passed to ssh.

Note a similar question was asked here:

http://www.perlmonks.org/?node_id=664789

The man page for ssh says:

-t      Force pseudo-tty allocation.  This can be used to execute arbitrary
        screen-based programs on a remote machine, which can be very useful, 
        e.g., when implementing menu services.  Multiple -t options force tty
        allocation, even if ssh has no local tty.
like image 725
WilliamKF Avatar asked Oct 15 '22 13:10

WilliamKF


1 Answers

One may work around the issue by passing -n to ssh instead of -t -t. From the ssh man page:

 -n      Redirects stdin from /dev/null (actually, prevents reading from
         stdin).  This must be used when ssh is run in the background.  A
         common trick is to use this to run X11 programs on a remote
         machine.  For example, ssh -n shadows.cs.hut.fi emacs & will
         start an emacs on shadows.cs.hut.fi, and the X11 connection will
         be automatically forwarded over an encrypted channel.  The ssh
         program will be put in the background.  (This does not work if
         ssh needs to ask for a password or passphrase; see also the -f
         option.)

So this is another way around the issue of stdin being taken from calling process and given to ssh, however, I'd like to understand how to avoid the warning when using -t -t.

like image 132
WilliamKF Avatar answered Oct 18 '22 14:10

WilliamKF