Sponsored Content
Operating Systems OS X (Apple) Bash script prompt for sudo password? Post 302310893 by PatGmac on Monday 27th of April 2009 09:56:43 AM
Old 04-27-2009
Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password.

So far I have:

Code:
if [[ "$(/usr/bin/whoami)" != "root" ]]; then 
    sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2
        if [ ! $? = 0 ]; then 
            echo "You entered an invalid password or you are not an admin/sudoer user. Script aborted."
            exit 1
        fi
fi

which does get the prompt, but the rest of the script does not run with sudo privileges as needed. What do I need to do for this to apply to the whole script?

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sudo in OS X shell script without password prompt??

I've written a shell script to alter a particular preference file on OS X (10.3.9), which works fine (tested by running the script from the terminal sat in front of the box). Problem is, I now have to run this script remotely across a number of machines via remote desktop, so where I've used the... (1 Reply)
Discussion started by: Brad_GNET
1 Replies

2. Shell Programming and Scripting

sudo, use in script without prompt for password

I need to create an automated script where I have to use sudo to switch to multiple user so the script stops and prompts for password, Is there a way I can provide the password in same command only? Remember that, I cannot disable the password settings of sudo as I dont have rights. (4 Replies)
Discussion started by: gauravgrover50
4 Replies

3. Shell Programming and Scripting

password in sudo script

salmo allikm warhmat allah wabrakato i want to do script with sudo like sudo su and want to put password in the script not get from user because i to made it startup when booting and i don't know how put in script for sudo thanks (5 Replies)
Discussion started by: pua06
5 Replies

4. UNIX for Dummies Questions & Answers

Sudo -s without password prompt

hi, i have a requirement where i need to sudo to another user in the shell script.suppose consider user A and B, first user A calls a shell script and then i need to sudo to user B which executes another shell script inside the earlier one. also this needs to be automated like while sudo'ing to... (3 Replies)
Discussion started by: krk
3 Replies

5. Shell Programming and Scripting

How to (GUI) prompt for password from bash?

I remember there was a gnome only command that we could insert in a bash script to mount a Linux disk that would pop up a little window to grab a password. I know there are bash commands to read a string but they are not GUIs and they echo the characters typed. This gnome command popped up a... (1 Reply)
Discussion started by: siegfried
1 Replies

6. Homework & Coursework Questions

Shell Script Password Prompt

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to write a shell script that prompts the user for the password which is "lux" once the correct password... (4 Replies)
Discussion started by: Emin_Em
4 Replies

7. Red Hat

Sudo Password Prompt over SSH

I am not sure what I am missing here. I have the following identical entry in /etc/sudoers on multiple Red Hat 6.4 servers. icinga ALL=NOPASSWD:/usr/bin/yum --security --exclude\="kernel*" check-update On one server when I enter the command over SSH as follows it works fine. ssh -t -q... (1 Reply)
Discussion started by: scotbuff
1 Replies

8. Shell Programming and Scripting

Make a password protected bash script resist/refuse “bash -x” when the password is given

I want to give my long scripts to customer. The customer must not be able to read the scripts even if he has the password. The following command locks and unlocks the script but the set +x is simply ignored. The code: read -p 'Script: ' S && C=$S.crypt H='eval "$((dd if=$0 bs=1 skip=//|gpg... (7 Replies)
Discussion started by: frad
7 Replies

9. Shell Programming and Scripting

How to add password prompt between script ?

Hi Team, I need password prompt between this script .i want to need put password manually. Instead of adding password in script . Script pause till input password and resume again. #!/usr/bin/expect set ip spawn telnet $ip expect "login:" send "USR\r" expect "*assword*"... (3 Replies)
Discussion started by: Ganesh Mankar
3 Replies

10. AIX

Sudo command prompt for a password

in the /etc/sudoer file this line was added: wtolentino ALL=(ORACLE) NOPASSWD: /bin/chmod when i tried to run this command sudo -u oracle /bin/chmod 775 /appshared/applications/lpa/executables/chrpt001.rep it prompts me for a password for example: $ pwd /appshared/applications/lpa... (2 Replies)
Discussion started by: wtolentino
2 Replies
KAS_SETPASSWORD(8)					       AFS Command Reference						KAS_SETPASSWORD(8)

NAME
kas_setpassword - Changes the key field in an Authentication Database entry SYNOPSIS
kas setpassword -name <name of user> [-new_password <new password>] [-kvno <key version number>] [-admin_username <admin principal to use for authentication>] [-password_for_admin <admin password>] [-cell <cell name>] [-servers <explicit list of authentication servers>+] [-noauth] [-help] kas setpasswd -na <name of user> [-ne <new password>] [-k <key version number>] [-a <admin principal to use for authentication>] [-p <admin password>] [-c <cell name>] [-s <explicit list of authentication servers>+] [-no] [-h] kas setp -na <name of user> [-ne <new password>] [-k <key version number>] [-a <admin principal to use for authentication>] [-p <admin password>] [-c <cell name>] [-s <explicit list of authentication servers>+] [-no] [-h] kas sp -na <name of user> [-ne <new password>] [-k <key version number>] [-a <admin principal to use for authentication>] [-p <admin password>] [-c <cell name>] [-s <explicit list of authentication servers>+] [-no] [-h] DESCRIPTION
The kas setpassword command accepts a character string of unlimited length, scrambles it into a form suitable for use as an encryption key, places it in the key field of the Authentication Database entry named by the -name argument, and assigns it the key version number specified by the -kvno argument. To avoid making the password string visible at the shell prompt, omit the -new_password argument. Prompts then appear at the shell which do not echo the password visibly. When changing the afs server key, also issue bos addkey command to add the key (with the same key version number) to the /etc/openafs/server/KeyFile file. See the OpenAFS Administration Guide for instructions. The command interpreter checks the password string subject to the following conditions: o If there is a program called kpwvalid in the same directory as the kas binary, the command interpreter invokes it to process the password. For details, see kpwvalid(8). o If the -reuse argument to the kas setfields command has been used to prohibit reuse of previous passwords, the command interpreter verifies that the password is not too similar too any of the user's previous 20 passwords. It generates the following error message at the shell: Password was not changed because it seems like a reused password To prevent a user from subverting this restriction by changing the password twenty times in quick succession (manually or by running a script), use the -minhours argument on the kaserver initialization command. The following error message appears if a user attempts to change a password before the minimum time has passed: Password was not changed because you changed it too recently; see your systems administrator OPTIONS
-name <name of user> Names the entry in which to record the new key. -new_password <new password> Specifies the character string the user types when authenticating to AFS. Omit this argument and type the string at the resulting prompts so that the password does not echo visibly. Note that some non-AFS programs cannot handle passwords longer than eight characters. -kvno <key version number> Specifies the key version number associated with the new key. Provide an integer in the range from 0 through 255. If omitted, the default is 0 (zero), which is probably not desirable for server keys. -admin_username <admin principal> Specifies the user identity under which to authenticate with the Authentication Server for execution of the command. For more details, see kas(8). -password_for_admin <admin password> Specifies the password of the command's issuer. If it is omitted (as recommended), the kas command interpreter prompts for it and does not echo it visibly. For more details, see kas(8). -cell <cell name> Names the cell in which to run the command. For more details, see kas(8). -servers <authentication servers>+ Names each machine running an Authentication Server with which to establish a connection. For more details, see kas(8). -noauth Assigns the unprivileged identity "anonymous" to the issuer. For more details, see kas(8). -help Prints the online help for this command. All other valid options are ignored. EXAMPLES
In the following example, an administrator using the "admin" account changes the password for "pat" (presumably because "pat" forgot the former password or got locked out of his account in some other way). % kas setpassword pat Password for admin: new_password: Verifying, please re-enter new_password: PRIVILEGE REQUIRED
Individual users can change their own passwords. To change another user's password or the password (server encryption key) for server entries such as "afs", the issuer must have the "ADMIN" flag set in his or her Authentication Database entry. SEE ALSO
bos_addkey(8), kas(8), kaserver(8), kpwvalid(8) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 KAS_SETPASSWORD(8)
All times are GMT -4. The time now is 09:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy