Trusted answers to developer questions

Error: mesg: ttyname failed: inappropriate ioctl for device

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

When running inline scripts Vagranta tool in the Ubuntu Linux environment for setting up a complete virtual development environment on Ubuntu, you may come across the following error.

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.

Why does the error show up?

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.

Solutions

Method 1

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

Method 2

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.

RELATED TAGS

operating system
ubuntu
vagrant
error
operating system

CONTRIBUTOR

Anusheh Zohair Mustafeez
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?