Coder Social home page Coder Social logo

Comments (16)

overcache avatar overcache commented on July 22, 2024 1

OK, Thanks for your work!

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

Does sudo-prompt ask for a password and then correctly call your command?

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024

yes it did. but what I expect is:

  • ask for password when command doesn't list in sudoers
  • run silently when command config with 'NOPASSWD'

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

Thanks @icymind

What does the following return?

  1. Open a brand new Terminal window.
  2. Run sudo -n echo hello

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024

Thanks for your reply. When I run your command, it just print 'sudo: a password is required' then exit.

🍉  sudo -n echo hello
sudo: a password is required

simon.mbp: ~ 
🍉   

more info, child_process works as expect, it didn't require a password :

const cmd = 'sudo /sbin/route change default "192.168.10.1"'
require('child_process').exec(cmd, {}, (err, stdout, stderr) => {
  if (err) {
    console.error(err)
  } else {
    console.log(stdout, stderr)
  }
})

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

Before asking for a password, sudo-prompt calls sudo -n.

This instructs sudo to run the command if a password is not required (if a sudo session is already established), or else to return the a password is required error.

If we see the error, we then ask the operating system to request administrator privileges on our behalf.

The issue here is that sudo itself is saying a password is required, yet when you run sudo without -n no password is actually required.

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

I am going to close this issue if it's fine with you:

  1. sudo itself is giving us the wrong feedback (saying a password is required when your sudoers says otherwise).

  2. It is unusual to allow password-less sudo privileges.

  3. sudo-prompt is technically still working correctly by requesting administrator privileges, and executing your command.

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024

so, there is no way to run a sudo command beyond a sudo session?

sorry for bothering you.

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

so, there is no way to run a sudo command beyond a sudo session?

No, none that I know of. You could take this issue up with the developers of sudo.

sorry for bothering you.

Anytime, let me know if you have any other questions.

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024

sorry, I still feel confused.

I think the reason why terminal reports error when I run sudo -n echo hello is that echo doesn't config as NOPASSWD

But /sbin/route is different, I successfully execute it in a new terminal:

simon.mbp: ~ 
🍉  sudo -n /sbin/route change default "192.168.10.1"
change net default: gateway 192.168.10.1

Please let me know if I misunderstanding

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

What does the following return?

sudo -k
sudo -n /sbin/route change default "192.168.10.1"

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024
simon.mbp: ~ 
🍉  sudo -k
sudo -n /sbin/route change default "192.168.10.1"
change net default: gateway 192.168.10.1

It execute without error.

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

Ah, thanks I see.

sudo -n is in fact checking your /etc/sudoers and seeing that no password is required for /sbin/route.

There should be no difference between that last command you tried and what sudo-prompt does (except for the -E flag that sudo-prompt also adds)?

See: https://github.com/jorangreef/sudo-prompt/blob/master/index.js#L11

If /usr/bin/sudo -n -E -- /sbin/route change default "192.168.10.1" succeeds, then Attempt() will finish immediately without calling Mac() (which is where we request administrator privileges).

So you should not be seeing a password prompt with sudo-prompt?

from sudo-prompt.

overcache avatar overcache commented on July 22, 2024
simon.mbp: ~
🍉  /usr/bin/sudo -n -E -- /sbin/route change default "192.168.10.1"
sudo: sorry, you are not allowed to preserve the environment

Then I add 'SETENV' to /etc/sudoers as what https://superuser.com/questions/636283/how-to-allow-user-to-preserve-environment-with-sudo/687347 says, now sudo-prompt runs well.

Is it a better solution to offer an option to toggle '-E' flag? When we use sudo, we don't use -E flag offen, isn't it?

from sudo-prompt.

jorangreef avatar jorangreef commented on July 22, 2024

We had an issue in the past regarding not having the -E flag, see: #20.

I would rather try and preserve environment variables than not.

from sudo-prompt.

bighitbiker3 avatar bighitbiker3 commented on July 22, 2024

I realize this thread is super old, but for some reason I can't get this to honor NOPASSWD, nor can I find the sudo -n call in the source code for this library. Did that get nixed sometime in the past few years?

from sudo-prompt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.