Security Bash Scripts – Why SUDO Password is Being Bypassed

bashscriptsSecuritysudo

I have a bash script I am using to automate a SVN checkout. The contents of the file were:

#!/bin/bash
cd /var/www-cake
sudo svn checkout file:///usr/local/svn/bash_repo/repo/

Then when I double click the file it would ask me what to do, I would click the button "Run In Terminal" and then a terminal would pop up and ask me for the SUDO password. I would enter it, the script would execute and the terminal would close.

I wanted to give some sort of indication that the script ran successfully so I edited my file to look like:

#!/bin/bash
cd /var/www-cake
sudo svn checkout file:///usr/local/svn/bash_repo/repo/
echo "Head revision has been pushed to live server"

I expected the terminal to now stay open and tell me the message afterwards. To my surprise it now opens and immediately closes. The script does execute and I no longer have to put in the SUDO password.

Is this right? I do not understand why this is happening, seems like a security issue.

Best Answer

sudo remembers your password for some time (15 minutes by default). You can make sudo to forget the password by running sudo -k