Search code examples
linuxsudo

Run sudo command with password


sudo command can be used in the following way

sudo -u <user_name> <command/script>

But I want to know how to include password as I want to avoid the user interactivity. Also, as an Admin, I don't want to disable password prompt for sudo commands. How can I achieve this. I tried man sudo, but not of much help.


Solution

  • You can use the -S switch that reads password from stdin, example:

    ~$  echo "yourpassword" | sudo -S <command>
    

    Anyway, as @Thrustmaster said, this is not the right way to use sudo.