55

Per the title, I'm getting the following warning when I try to scp through an ssh tunnel. In my case, I cannot scp directly to foo because port 1234 on device foo is being forwarded to another machine bar on a private network (and bar is the machine that is giving me a tunnel to 192.168.1.23).

$ # -f and -N don't matter and are only to run this example in one terminal
$ ssh -f -N -p 1234 userA@foo -L3333:192.168.1.23:22
$ scp -P 3333 foo.py ubuntu@localhost:
ubuntu@localhost's password:
stty: standard input: Inappropriate ioctl for device
foo.py                                          100% 1829     1.8KB/s   00:00

Does anyone know why I might be getting this warning about Inappropriate ioctl for device?

jonderry
  • 23,013
  • 32
  • 104
  • 171

3 Answers3

93

I got the exact same problem when I included the following line on my ~/.bashrc:

stty -ixon

The purpose of this line was to allow the use of Ctrl-s in reverse search of bash.

This gmane link has a solution: (original link dead) => Web Archive version of gmane link

'stty' applies to ttys, which you have for interactive login sessions. .kshrc is executed for all sessions, including ones where stdin isn't a tty. The solution, other than moving it to your .profile, is to make execution conditional on it being an interactive shell.

There are several ways to check for interecative shell. The following solves the problem for bash:

[[ $- == *i* ]] && stty -ixon
StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
mMontu
  • 8,983
  • 4
  • 38
  • 53
  • 7
    Explanation of "[[ $- = *i* ]]" found here (I certainly needed it): http://stackoverflow.com/questions/31155381/what-does-i-mean-in-bash/31155446 – Alex Jansen Feb 13 '17 at 22:37
  • 1
    Glad you pasted the text from the link, as it looks like that link is dead now, and some quick searching doesn't turn up a new URL for it. – Randall Feb 15 '17 at 16:44
  • @Randall the link is dead indeed. But I hope it is temporary, as mentioned at [their homepage](http://gmane.org/). – mMontu Feb 16 '17 at 11:12
  • Nope. It's gone. – TonyG Nov 19 '18 at 04:14
  • exactly the same problem. Interestingly I was getting this as an error popup on initial login on ubuntu when the offending call was in my `.profile`. I'm a little surprised its getting sourced but hopefully this should fix – JonnyRaa Nov 20 '18 at 10:39
  • Another common practice is just to put `[[ "$-" != *i* ]] && return` at the top of `.bashrc` – Dmitry Oct 09 '19 at 09:03
  • Should I put this line into `.zshrc` as well? – alper Sep 24 '21 at 12:14
3

Got the same issue while executing the script remotely. After many tries didn't get any luck to solve this error. Then got an article to run a shell script through ssh. This was an issue related to ssh, not any other command. ssh -t "command" -t will allocate a pseudo TTY to the ssh and this error won't come.

Arun Kumar
  • 41
  • 1
-3

at the end i created a blank .cshrc file ( for ubuntu 18.04). worked

ark
  • 1
  • Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. –  Jul 25 '20 at 20:24