0

When I try to run a script on a remote server using ssh, I am getting "no tty present and no askpass program specified" error.

Main Command line where I am getting error is:

sudo /usr/sbin/userdel $user_id

Please suggest what need to modify in my command line.

NOTE: I can't modify sudoers file on remote server.

  • Thanks Filipe it's worked for me but I am now facing new error. Usage : userdel [options] LOGIN Options : -f , -- force -h , -- help -r , -- remove -R,. -- root CHROOT_DIR -z, -- selinux-user – Rahul Raj Apr 18 '18 at 15:34
  • Looks like your script on the remote host is missing an option to the userdel command, such as the name of the user to remove... Can you check that? See the script you're running, check how it's selecting the user to be removed and try to figure out why it might be missing... It might be helpful to add a -x to your command to print the exact commands executed, as in ssh $host bash -x /path/to/myscript.sh. I hope this helps! – filbranden Apr 18 '18 at 15:45
2

You should pass ssh the -t option, so it allocates a tty (terminal) on the remote side for running your script.

Commands that need to prompt for a password (such as sudo) need a terminal, so they can control terminal I/O, such as preventing output of typed characters, so your password doesn't appear while you're typing it.

When you run ssh $host (with no command), the SSH client will automatically allocate a terminal (so no -t is needed), but if you run it with a command, such as ssh $host /path/to/script then it will not allocate a terminal, since for most commands a terminal is not needed and simply redirecting the standard file descriptors (stdin, stdout, stderr) is enough... The -t option changes that behavior and allocates a terminal even though you're passing it a command line.

See the documentation of the -t option in the SSH man page. Look for other references to pty or pseudo-terminal on that page (BTW, they call it pty/pseudo-terminal instead of tty since the terminal is not attached to a real device such as a keyboard/monitor or a serial port... for these purposes, it means about the same.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.