Today I Learned: 08/12/2022 - /dev/tty errors using scp in Docker
I hit an unexpected error today while using scp in a script executing in a Docker container - an inability to use a tty. This was correct in that I wasn’t running Docker with the interactive or terminal flags (commonly used as -it). The relevant -vv output from scp was:
debug1: read_passphrase: can’t open /dev/tty: No such device or address
Host key verification failed.
lost connection
What confused me is that I was explicitly providing a key file without a passphrase.
Some headscratching later, I found the error was a little misleading - scp did need a tty, but not to ask for a passphrase. It wanted permission to override the existing host key details of my remote server in the ~/.ssh/known-hosts file. Since my Docker container was intended to be removed after each run, this was most easily fixed by telling scp not to check the key, by adding
to the arguments.