- Storing your bash scrpits
One of better ways to store scripts created by yourself is to create bin folder in your home direcotry and add it to path where bash is looking for scripts.
- Create bin folder.
mkdir ~/bin
- Add it to PATH in .bashrc configuartion file.
nano ~/.bashrc
And at the end of file write:
export PATH="$HOME/bin:$PATH"
After doing that you can run scrpits from bin folder just by typing their name.
- Execute script without sudo password Before doing that you must remember that this step can cause some danger to the system beacuse you allow to execute any command in particular script without sudo password. So keep that in mind while choosing files.
I recommend to pass file ownership to root and allow other users only to execute it. It will block possibility of changing a file if you are not a root and make adding some extra lines without your knowledge more difficult.
- Changing file owner to root and leaving only execute option to others users. (not reqiured)
chmod +x <filename>
chmod o-rw <filename>
sudo chown root:root <filename>
- Putting choosen file to run without sudo password.
sudo visudo
Add at the end of file:
<username> ALL = NOPASSWD: <file_path>