Getting Stty: Standard Input: Inappropriate Ioctl for Device When Using Scp Through an Ssh Tunnel

stty: standard input: Inappropriate ioctl for device

I think the problem is you are reading from a redirected STDIN (because you <file.txt)

$ perl -e 'system("stty -echo");' </tmp/foo
stty: standard input: Inappropriate ioctl for device

You should probably pass your file as a parameter to your script.

Errno::ENOTTY Inappropriate ioctl for device when connecting to a remote server through Net::SSH on SuSe (with Ruby on Rails 5.2.4)

I finally found out that the message refers to the operating mode of SSH: it requires a sort of terminal emulation - so called pty - wrapped into a SSH chanel.

So I implemented it this way:

Net::SSH.start(remote_host, remote_user, password: remote_password) do |session|
session.open_channel do |channel|
channel.request_pty do |ch, success|
raise "Error requesting pty" unless success
puts "------------ pty successfully obtained"
end

channel.exec "#{@task.statement}" do |ch, success|
abort "could not execute command" unless success

channel.on_data do |ch, data|
puts "------------ got stdout: #{data}"
@task.update_attribute(:return_value, data)
end

channel.on_extended_data do |ch, type, data|
puts "------------ got stderr: #{data}"
end

channel.on_close do |ch|
puts "------------ channel is closing!"
end

end
end

### Wait until the session closes
session.loop
end

This solved my issue.

Note:
The answer proposed above was only a part of the solution. The same error occured again with this source code when deploying to the production server.

The issue appears to be the password to the SSH target: I retyped it by hand instead of doing the usual copy/paste from MS Excel, and the SSH connection is now successful!

As the error raised is not a simple "connection refused", I suspect that the password string had a specific character encoding, or an unexpected ending character.

As the first proposed solution provides a working example, I leave it there.

How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?

The stty problem is not related to your environment, it's a result of the SSH command not allocating you a TTY (What is Pseudo TTY-Allocation? (SSH and Github)). Adding -t argument for ssh should fix it.

Further information:

  • http://go2linux.garron.me/linux/2010/11/ssh-t-open-pseudo-tty-run-commands-remote-server-809/
  • http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/

Pseudo-terminal will not be allocated because stdin is not a terminal

Try ssh -t -t(or ssh -tt for short) to force pseudo-tty allocation even if stdin isn't a terminal.

See also: Terminating SSH session executed by bash script

From ssh manpage:

-T      Disable pseudo-tty allocation.

-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.


Related Topics



Leave a reply



Submit