When running inline scripts
mesg:
ttyname failed
:
Inappropriate ioctl for device
In this shot, we will cover some possible reasons behind this error and show how to resolve it.
Vagrant’s default SSH shell command is bash -l
, which prompts Vagrant’s internal SSH communicator. This becomes a login shell as the l
flag is used.
For a non-interactive login shell like this one, bash will source /etc/profile
, followed by the first existing file out of ~/.bash_profile
, ~/.bash_login
, and ~/.profile
. Vagrant runs most of its commands as root so it will source /etc/profile
, then /root/.profile
.
The /root/.profile
contains the mesg n
command on Ubuntu. This command ensures that no other user can write to your terminal device. However, when running commands on Vagrant, there is no terminal device, so the mesg n
command is not compatible. This will lead to the error.
Open the /root/.profile
file and replace mesg n || true
with tty -s && mesg n
. This method works since the mesg -n
command is only called if a terminal device is present (determined by the tty
command).
Another fix is to avoid using a login shell altogether. We can do this by changing the config.ssh.shell
Vagrant setting to bash
, without the l
flag.