---
title: "What Is Rex TTY? Fixing Rex Sudo and TTY Errors"
url: "https://goremy.ai/blog/articles/rex-tty"
author: Luis Chavez-Mattos
editor: Luis Chavez-Mattos
editor_title: Director, Product
published: "2026-11-28T12:20:18.602Z"
updated: "2026-11-28T12:20:18.602Z"
topic: Cybersecurity and IT Systems
description: "Rex tty explained: what TTY means in Rex automation, why sudo fails with a tty error, and how to fix requiretty on Linux servers."
---

# What Is Rex TTY? Fixing Rex Sudo and TTY Errors

> Rex tty explained: what TTY means in Rex automation, why sudo fails with a tty error, and how to fix requiretty on Linux servers.

Edited by Luis Chavez-Mattos, Director, Product · Published 2026-11-28

## What is Rex TTY?

"Rex TTY" is not a product. It is shorthand for a problem that shows up when you use Rex, the Perl-based tool for automating work on remote servers, and a command needs a terminal that isn't there. TTY stands for teletypewriter, the old name for a terminal. Rex runs your commands over SSH without anyone sitting at a keyboard. Some programs, most often `sudo`, refuse to run without a terminal. The result is an error like "you must have a tty to run sudo."

## TL;DR

- **TTY means a terminal session.** A person typing at a prompt has one. An automated tool running a single command over SSH usually does not.
- **Rex tasks run without a person**, so commands that expect a terminal can fail even though they work when you type them by hand.
- **The most common cause is `requiretty` in the sudoers file.** Some Linux setups, mainly older Red Hat family systems, ship with it turned on.
- **The cleanest fix is on the server.** Turn off `requiretty` for the one account Rex uses, rather than for everyone.
- **A different message, "no tty present and no askpass program specified,"** means sudo wants a password and has no way to ask. That needs a password setting or a narrowly scoped passwordless rule.
- **Forcing a pseudo-terminal is a fallback.** It can change output and behavior, so fix the server rule first.

## Why do other results for "rex tty" look unrelated?

"Rex" is a common name. Search for it and you will find remote-control toy dinosaurs, fossil news, radio exercises, and unrelated command-line utilities. None of that has anything to do with this topic. This article is about Rex, the open-source automation framework (rexify.org) where you write tasks in Perl, usually in a file called a Rexfile, and run them against one or many servers over SSH. People use it for the same kind of work as Ansible or Chef: installing packages, copying config files, restarting services, deploying code.

## What does TTY mean?

A TTY is a terminal device. The name comes from teletype machines, which were the first way people typed commands to computers. Today it means any terminal session, whether a window on your laptop or an SSH login.

When you log in to a server and type commands, the system gives you an interactive session with a terminal attached. Programs can see this and behave accordingly. They can print colors, ask questions, and wait for a password.

You can check this yourself. Run this on a server:

```
tty
```

In a normal login it prints something like `/dev/pts/0`. Now run it as a one-off remote command:

```
ssh user@server 'tty'
```

You will typically get "not a tty." That second case is how automation tools usually work, and it is the root of most Rex tty errors.

## Why do Rex tasks fail when no terminal is attached?

Rex connects to a server over SSH and runs each command as a separate remote command. By default, SSH does not allocate a pseudo-terminal (a "pty," a fake terminal the system hands out) for those commands. Nobody is there to type, so there is no reason to.

Most commands do not care. `ls`, `cat`, and `systemctl status` run fine. Trouble starts with commands that check for a terminal. The usual one is `sudo`.

Many Rex tasks need root privileges, so they call `sudo`. If the server's sudo configuration says a terminal is required, sudo stops and prints:

```
sudo: sorry, you must have a tty to run sudo
```

That setting is `requiretty`. It was a default on some Red Hat family distributions for years, and it still turns up on older or hardened machines. Newer releases generally don't enable it by default, but a server built from an old image or a security baseline may still carry it.

This is why the failure feels confusing. The same `sudo` command works when you SSH in and type it. It fails only when Rex runs it.

## How do I fix "you must have a tty to run sudo"?

Change the sudo rule for the account Rex logs in as. Do not edit the main sudoers file by hand with a normal editor. Use `visudo`, which checks syntax before saving, because a typo in sudoers can lock you out of root access.

1. Log in to the server with an account that already has admin rights.
2. Create a dedicated file with `visudo`:

```
sudo visudo -f /etc/sudoers.d/rex
```

3. Add a line that turns off `requiretty` for only the Rex user. Here the user is named `deploy`:

```
Defaults:deploy !requiretty
```

4. Save and exit. `visudo` will warn you if the syntax is wrong.
5. Test it the way Rex will run it, as a one-off remote command:

```
ssh deploy@server 'sudo -n true' && echo OK
```

If it prints OK, the tty problem is gone. If you would rather not touch individual files, you can find the global `Defaults requiretty` line in `/etc/sudoers` and remove it. Scoping the change to one user is the more careful choice because it limits what you are loosening.

## What if sudo says "no tty present and no askpass program"?

This message is related but different. It means sudo wants a password and has no terminal to prompt on. You have two sensible options:

- **Give Rex the sudo password.** Rex has settings for the sudo password. Check the documentation for your version for the exact option and how to keep the password out of your Rexfile, for example by reading it from an environment variable or a secrets store.
- **Allow passwordless sudo for specific commands.** This is common for service accounts that use SSH keys:

```
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/apt-get
```

Listing exact commands is safer than `NOPASSWD: ALL`. If your tasks really do need broad access, make that a deliberate decision and document it, since anyone who gets that SSH key gets root.

The `-n` flag in `sudo -n true` is a useful test here. It tells sudo never to prompt, so it fails immediately if a password would be needed.

## Should I force a pseudo-terminal instead?

You can ask SSH to allocate a terminal even for a one-off command by using `ssh -t`. Some automation tools expose an equivalent setting. This can get around `requiretty` without changing the server.

It is a workaround, and it has costs:

- Output may include terminal control characters or merge error and normal output, which can confuse tasks that parse results.
- Commands that detect a terminal may switch to interactive behavior, such as paging or prompting.
- You are leaving the server rule in place, so the next tool that connects without a terminal fails the same way.

Rex's configuration includes options that affect sudo and terminal behavior, and they have changed between versions. Check the documentation for the version you run (`rex -v` shows it) rather than copying a setting from an old forum post.

## What this means for you

If you are a sysadmin or developer who inherited a Rexfile, the fix above usually takes a few minutes. Test with `ssh user@server 'tty'` and `sudo -n true` before you blame Rex itself.

If you are on a team where someone else owns the servers, bring them the exact error text and the exact sudoers line you want. "Add `Defaults:deploy !requiretty` for the deploy account" is an easy request to approve. "Fix sudo" is not.

If you are a manager or analyst who just saw "tty" in a failed job log, you can read it plainly: the automation hit a command that wanted a person at a keyboard. It is a configuration issue, not a sign the deployment tool is broken or the servers are compromised.

Whoever fixes it, keep a short record of which servers have which sudo exceptions. That list matters for audits and for the day someone asks why a service account has root.

## Is there an easy way to track server fixes like this?

Problems like this tend to live in someone's notes or a spreadsheet: which hosts have `requiretty`, which service accounts have passwordless sudo, who approved it. If you want that in one place, a small internal tracker with a request form for sudo exceptions and a status column per server is a reasonable thing to build for yourself. You can describe it in plain English to [Remy](https://goremy.ai), which builds and deploys a full-stack app from that description, with sign-in and a database included, so the list isn't scattered across files and subscriptions.

## Frequently Asked Questions

### What does TTY stand for?

TTY stands for teletypewriter. In modern systems it means a terminal session, either a real one on your screen or a pseudo-terminal (pty) created for an SSH login. Programs use it to decide whether a person is present to type input.

### Why does sudo work when I log in but fail in Rex?

When you log in interactively, SSH gives you a terminal. When Rex runs a command over SSH, it typically has none. If sudo is set to `requiretty`, it accepts your login session and rejects Rex's.

### Is it safe to remove requiretty?

Generally yes. The setting offered little real protection, since anyone who can run commands can usually get a terminal anyway, and many current distributions leave it off. Still, limit the change to the one account Rex uses and keep the sudo permissions for that account as narrow as you can.

### Does this error mean Rex is broken?

No. It means the server's sudo policy and the way Rex connects disagree. Once you adjust the sudoers rule or provide a password, the same task runs normally.

### Where do I put the sudoers change?

Use `sudo visudo -f /etc/sudoers.d/yourfile` to create a small drop-in file. It is easier to review and remove later than an edit to the main sudoers file, and `visudo` checks syntax before saving.
