-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run commands as a different user (sudo -i) #122
Comments
Sounds like a good idea, and also one that should be easy to add. The only hard part would be in surfacing good error messages and creating automated testing. I don't think think this is Unix specific. The second approach should work. |
Cool! Question: In addition to setting |
Up to you. I usually add things when I need them |
I started to implement this, but I realized that there is a problem. All of shelly's builtin commands, such as I'm thinking it might be cleaner/better to go with option (1) that I proposed above. Anyway, I will think about this for a bit before proceeding and of course would be interested in hearing other thoughts. btw, I noticed that there is a commented out |
You are right, that is problematic. I don't think If the only use case is to run as sudo, a |
Regarding
|
hmm. If I have sudo in a bash script it will prompt me to elevate privileges. Maybe this is a weakness to not using bash. When starting the script as root, there isn't a clear way to copy a file as non-root. So |
I'm not sure if I understand what you meant, but if you have a bash script that does: #!/bin/bash
# /etc/shadow is only readable by root
sudo cat /etc/shadow Then it will run the "/usr/bin/sudo" command, which will prompt for a password, and then it is the sudo program itself that will run In the case of shelly, it is possible to do something similar: run "/usr/bin/sudo" with the proper arguments, in order to run the command |
ahh, ok. Does it make sense to have an |
A nice feature to have would be the ability to run a command as a different unix user (sudo -i).
Haskell's
process
package supports this with thechild_group
andchild_user
fields ofCreateProcess
[1]I can think of two ways for Shelly to support this:
run
andrun_
functions that take an extra UserId argumentwithUser :: UserId -> Sh a -> Sh a
that starts a sub-Sh in which all commands will be run as the requested UserId. This requires adding field(s) toShelly.State
Either way, this functionality would probably belong in the
Shelly.Unix
module.I would appreciate feedback on this idea, and I can work on a pull request.
[1] https://hackage.haskell.org/package/process-1.4.2.0/docs/System-Process.html#t:CreateProcess
The text was updated successfully, but these errors were encountered: