13
3
I had already asked this question in Stack Overflow, but I've been asked to post it here. So doing the same.
I ran this command using my java program-
sudo -u <username> -S pwd
I got this output-
command=sudo -u <username> -S pwd
exitCode=1
sudo: sorry, you must have a tty to run sudo
I tried editing /etc/sudoers but it already contains
<username> ALL=(ALL) NOPASSWD: ALL
Then, I learned that this can be done by commenting out the following code in /etc/sudoers
# Defaults requiretty
Also, by default, when attempting to execute a command as another user using sudo
, we have to provide our own password. But this can be changed by making the following change in /etc/sudoers-
Defaults targetpw
My Question is, is it possible to execute my above command in java without making any changes anywhere i.e. by having default settings?
1
Is this why you were asking the rather contrived Alternative for sudo?
– slhck – 2013-08-19T09:00:33.5106
Seems distro specific if
– mpy – 2013-08-19T09:32:59.373requiretty
is enabled by default. According tosudo
's own documentation it is "off by default."