Comments (16)
OK, Thanks for your work!
from sudo-prompt.
Does sudo-prompt
ask for a password and then correctly call your command?
from sudo-prompt.
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.
Thanks @icymind
What does the following return?
- Open a brand new Terminal window.
- Run
sudo -n echo hello
from sudo-prompt.
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.
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.
I am going to close this issue if it's fine with you:
-
sudo
itself is giving us the wrong feedback (saying a password is required when your sudoers says otherwise). -
It is unusual to allow password-less sudo privileges.
-
sudo-prompt
is technically still working correctly by requesting administrator privileges, and executing your command.
from sudo-prompt.
so, there is no way to run a sudo
command beyond a sudo session?
sorry for bothering you.
from sudo-prompt.
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.
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.
What does the following return?
sudo -k
sudo -n /sbin/route change default "192.168.10.1"
from sudo-prompt.
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.
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.
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.
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.
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)
- 'Command failed' in Electron app HOT 1
- Not possible in Mac App Store, aka app-sandbox HOT 5
- macOS Catalina Operation not permitted HOT 1
- OS dialog prompt is not being prompted in Windows 10 HOT 1
- Operation not permitted in macOS with sudo-prompt
- Prompt shows but name and icon are not visible on macOS HOT 8
- "User did not grant permissions" if I click "Yes" too quickly on Windows? HOT 1
- `sudo-prompt` fails to detect `pkexec` or `kdesudo` in "strictly" confined snap
- Special characters handling on Linux
- Strange behaviour with Electron 9 on Win10 HOT 1
- in Eelectron app Rendering process, sudo run cp not work
- Hello, why option.name just support [a-z0-9 ] ?
- How to get elevated shell and run a command without sudo prefix HOT 1
- macOS: Application cannot be opened because the developer cannot be verified
- BigSur 11.1 issue: The authorization was denied since no user interaction was possible HOT 1
- Linux: option.env not used
- Unexpected behaviour with linux - electron.js HOT 1
- electron exe with root system privileges in linux, It's possible to do ?
- How to run multiple commands without requiring password every time HOT 6
- Any pkg similar to this, but without root/admin?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sudo-prompt.