3

Was trying to figure out how to execute a sudo command with the password as a parameter.

echo mypassword | sudo -S command

was using this reference Use sudo with password as parameter

However, on OS X it keeps say "sudo: incorrect password attempt" however that passwords is correct.

what am i doing wrong?

Community
  • 1
  • 1
Lacer
  • 5,668
  • 10
  • 33
  • 45
  • 6
    Just a tiny remark: this is a very bad idea. For example, if you type this into your command line, your password will be stored in your shell history. I have no idea what you're up to, but I think you're calling for trouble ;) – tamasgal Oct 22 '16 at 23:16

1 Answers1

3

As pointed out in the comments already, what you're doing is a very bad idea because it leaves the password of an account laying around. Instead, if you need to run a specific command with sudo from a script, you could -- and you should -- define that single command for one specific user in such a way that its execution is allowed without having to type in the password.

So, you should edit /etc/sudoers to include an entry for your specific user for that one, single, specific command with the tag NOPASSWD:

youruser yourhostname = (root) NOPASSWD: /some/path/your/command

Or if you really don't feel like typing in the hostname of your computer, then go for:

youruser ALL = (root) NOPASSWD: /some/path/your/command

That way you will possibly leak the ability of executing that one, single command as root instead of leaking your password and with it the possibility of running any commands as root.