Remote sudo needs a password input mechanism to run privileged commands over SSH when authentication is required. Without one, it fails with no tty present and no askpass program specified or a similar password error. Interactive commands can use a forced pseudo-terminal for the prompt, while unattended jobs need a command-specific NOPASSWD rule or an approved askpass helper.

OpenSSH allocates a pseudo-terminal for normal interactive logins, but a remote command such as ssh user@host sudo id runs as a non-interactive session unless a tty is requested. sudo can read a password from the user's terminal, from standard input with -S, or from an askpass helper with -A and SUDO_ASKPASS; without one of those inputs it exits before running the privileged command.

Use a forced tty for a human-run remote command where typing the sudo password is acceptable. For scheduled jobs and CI, keep the SSH session non-interactive, configure a sudoers NOPASSWD rule limited to the exact executable and permitted arguments, and add sudo -n so the job fails clearly instead of waiting for a hidden prompt.

Steps to fix “no tty present and no askpass program specified” over SSH:

  1. Reproduce the failing remote sudo command without a tty.
    $ ssh user@host.example.net sudo id
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a password is required

    Older sudo releases may show sudo: no tty present and no askpass program specified for the same password prompt failure.

  2. Force tty allocation for a one-off command so you can type the remote account's sudo password at the prompt.
    $ ssh -tt user@host.example.net sudo id
    [sudo] password for user:
    uid=0(root) gid=0(root) groups=0(root)
    Connection to host.example.net closed.

    -tt forces OpenSSH to request a pseudo-terminal even for a remote command.

  3. Open a dedicated sudoers drop-in on the SSH server for unattended jobs.
    $ sudo visudo -P -f /etc/sudoers.d/zz-user-id

    Do not pipe a plaintext password into sudo -S from reusable scripts, CI logs, shell history, or process arguments. A NOPASSWD rule lets any process using the named account run its allowed command as root without a password. Substituting a shell, editor or other program with unrestricted behavior can grant root access.

    -P gives the new file the default sudoers permissions. Drop-in files load in lexical order, so zz-user-id follows earlier drop-ins that might require a password for the same account.

  4. Add the argument-free /usr/bin/id rule using the real account name instead of user.
    user ALL=(root) NOPASSWD: /usr/bin/id ""

    The "" suffix permits no arguments; omitting it allows arbitrary arguments. Other commands need their own executable and argument restrictions.
    Related: How to allow a specific program for a user or group in sudo

  5. Exit the editor with the rule saved.
  6. Validate the sudoers policy before relying on the rule.
    $ sudo visudo -c
    /etc/sudoers: parsed OK
    /etc/sudoers.d/README: parsed OK
    /etc/sudoers.d/zz-user-id: parsed OK
  7. Verify that the remote command works without a tty or password prompt.
    $ ssh user@host.example.net sudo -n /usr/bin/id
    uid=0(root) gid=0(root) groups=0(root)

    If this still reports that a password is required, check the command path with command -v id and look for a later sudoers rule that overrides the NOPASSWD tag.

Share this guide