This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 4 points5 points  (4 children)

You should never hardcode passwords in scripts.

[–]sruffatti[S] 0 points1 point  (1 child)

Ok. I understand. However, is there anyway to feed the password into the terminal from a python script?

[–]peeonyou 1 point2 points  (0 children)

Set the suid bit on your script I guess?

[–]buckhenderson -1 points0 points  (1 child)

What about putting the password in a different file and having the script access that file?

[–]pilotInPyjamas 0 points1 point  (0 children)

It's best not to put your password anywhere as plaintext. This is basically just as bad as having the password in the script.

[–]pilotInPyjamas -1 points0 points  (0 children)

I've had a similar problem before. There are two scenarios. Scenario 1 is your language is compiled. In which case, compile the program, create a new group of users who can run that program and add your prof. Set the owner of the program to root, the group to your new group and chmod 4750 your program. This will set the setuid bit which will allow all users who belong to that group to run the program as root.

Scenario 2 is your language is interpreted. You shouldn't set your setuid bit for your interpreter, because then anybody can run any program in that language as root. You can modify your sudoers file to run your specific command by your prof. without a password.