I want to run a few scripts when I start an interactive shell on my system. As I understand it, putting these commands in .bash_login should do the trick. Unfortunately, some of these commands require sudo. So how would I run such commands from .bash_login?
1 Answer
I guess the problem is sudo asking for password?
If yes, then for these particular commands that you want to run from your .bash_login
file, use NOPASSWD option in /etc/sudoers
file.
Assume you want to run for example the following command from .bash_login
:
sudo rm /etc/someconfigfile
Then put the following line into /etc/sudoers
(this file should be edited using visudo
command):
myuser ALL=(root) NOPASSWD: /bin/rm /etc/someconfigfile
It means that user myuser
is allowed to run command /bin/rm /etc/someconfigfile
(you can use wildcards here) as root
without asking for password.
For more detailed explanations, look man sudoers
.