I have this code in a linux executable file to start atom from there:
#! /bin/bash
sudo atom
I wanted to include sudo password after that lines of code, so the program will run automatically.
Join Stack Overflow to learn, share knowledge, and build your career.
I have this code in a linux executable file to start atom from there:
#! /bin/bash
sudo atom
I wanted to include sudo password after that lines of code, so the program will run automatically.
I wouldn't suggest hardcoding a password into your script as it carries a security risk.
Strictly speaking you can by doing:
echo "yourpassword" | sudo -S <command>
The -S
flag will read the password from stdin.
There is another better way for you to allow password-less sudo commands by modifying your sudoers file.
Why you not use sudoers? Try running atom without password.
Edit /etc/sudoers
via visudo:
visudo -f /etc/sudoers
Put new line and save:
youuser ALL=(ALL:ALL) NOPASSWD: atom
do not forget to replace youuser
You dont need this. You need to use visudo:
sudo visudo
Then add line like this:
username ALL=(root) NOPASSWD: /path/to/script.sh
And then run your script using sudo script.sh
without password
sudo -S
. – KamilCuk Apr 18 '19 at 8:47visudo
and set the appropriate permissions for this user to runsudo
without a password (you will probably have to add the user to thewheel
(or lately thesudo
) group as well. – David C. Rankin Apr 18 '19 at 8:47