Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Im looking for a way to link some bash scripts. Kinda the way you include php. I wanna have my password.sh ask for pass > launch Utility > Utility checks to see if its correct > if so it will move to next step > .. Some thing like that. I assume i would have top use a file to store my msd5 coded password (im sure ill find a way to lock that down).

So is this a possible task? if so were should i start reading? if now what would be a better lang to use for that function. but still using my bash as backend?

share|improve this question
    
Best look first on google, found this one: [How to include file in a bash shell script][1] [1]: stackoverflow.com/questions/10823635/… –  nickanor Dec 28 '12 at 19:16
1  
Sounds like what you really want is to verify that a user has entered his own password before doing something else. Encoded passwords are in /etc/shadow which only root can read, so if you want to read shadow file, you'll have to do something like create a setuid C program which does the encoding and chks if the encoded Pswd is the same as in /etc/shadow. As far as I know, shell scripts cannot run as setuid. –  Chris Good Dec 30 '12 at 8:51
1  
Just after I made my last post, I realised that asking people to enter their Unix password is a bad idea as they would need to trust that you are not going to do anything bad with it... –  Chris Good Dec 30 '12 at 20:56
1  
Need more clarification with example if possible –  totti May 14 '13 at 10:25

2 Answers 2

You can insert some python script inside your bash script to check for passwords in your keyring.

1) Open seahorse and copy the name of your password (example "Ubuntu One").

enter image description here

2) Inside your script, this is how you can get the password (change "Ubuntu One" to the name of your password).

#!/bin/bash
password=`
python << END
import gnomekeyring as gk

keyring = gk.get_default_keyring_sync()
keyItems = gk.list_item_ids_sync(keyring)

if not gk.get_info_sync(keyring).get_is_locked():
    for i in keyItems:
        key = gk.item_get_info_sync(keyring, i)
        if  key.get_display_name() == 'Ubuntu One':
            print key.get_secret()
END` 

echo "This is the password in your keyring which name is \"Ubuntu One\": $password "
exit 0
share|improve this answer

It seems you need to keep some secret in your script and it doesn't seems to be a right place for that.

Think about that: script needs to be readable by the user to be interpreted by bash, how would you prevent user from copying the script, removing any checks from it and executing this modified version?

You'd better use some external utility for password check, for example use gnome keyring as suggested by @desgua

Also, if you want user to input THEIR OWN password, you may try a trick with sudo, say you'll do it for tester username:

  1. change owner of a script to some other user (I'll call it admin in this example): chown admin /path/to/script.sh
  2. make script accessible only by this user chmod 700 /path/to/script.sh
  3. give users that should run this script sudo rights to execute this script (you may limit their sudo rights to ONLY this script), to do so add something like this to /etc/sudoers file (use visudo to edit this file): tester ALL = (admin) /path/to/script.sh

  4. now user tester could run sudo -u admin /path/to/script.sh and will be asked for HIS OWN password by sudo. He won't be able to run other commands on the name of admin or read script content.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.