sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.14k stars 209 forks source link

use_pty should be off for root #338

Open dag-erling opened 6 months ago

dag-erling commented 6 months ago

The use_pty option was recently turned on by default (cf. #358). While this makes sense when for non-root target users, it does not make sense for root, and it breaks typeahead in the extremely common case of using sudo to run adminstrative commands interactively in a terminal. Please turn it off for root, either in code or by adding the following line to the default sudoers file:

Defaults>root !use_pty
razamatan commented 4 months ago

visudo was messing up my term session until i added this fix for root. it also messed up nested commands that required reading from the tty which scripts do.

(fyi, correct issue reference for the default setting is #258)

razamatan commented 4 months ago

to also capture a potential use_pty bug, i had to unset this for root b/c i was doing a nested command that read from the tty that no longer waited for input and just went on.

# using bash

# works as expected
$ printf '<%s>\n' "$(read -rp 'type something: ' var && printf %s $var)"
type something: foo
<foo>
$

# fails w/ use_pty on or off
$ printf '<%s>\n' "$(sudo read -rp 'type something: ' var && printf %s $var)"
read[9]: read: no query process
<>
$