Find the answer to your Linux question:
Results 1 to 8 of 8
Hi I want to write a shell script for the following scenario. when person wants to change the user, He/She types : su - then system asks password. I want ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4

    Shell script

    Hi

    I want to write a shell script for the following scenario.

    when person wants to change the user, He/She types : su -

    then system asks password.

    I want to automate in a way that "su -" command will automatically take password from my script.

    can anybody tell me, if it is possible and how ??

    Thanks a lot.

    bye.

  2. #2
    Linux Newbie Ziplock's Avatar
    Join Date
    Jan 2009
    Location
    Adelaide
    Posts
    169
    What are you trying to achieve?

    Running su without a password for all commands is basically giving people administrator access... I would not recommend it at all - EXTREMELY insecure. Also, by putting the password in a file, you are also giving them root password as the script is probably going to need to be readable...

    You can tie it down to a couple of commands that you want to run though. This would enable you to do something like 'let mary and joe run the shutdown command without a password', without giving them complete administrator privileges.

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4
    I will only run that script for me.....

    no access is allowed..

    Is it possible.

  4. #4
    Linux Newbie
    Join Date
    Feb 2009
    Posts
    99
    mabye su can not use in script. try sudo. it's better.

  5. #5
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4

    Thumbs down

    supppose this is the shell script:

    #!/bin/sh
    sudo su

    When I will run it it wil ask me for password.

    But I want to make it like that I can provide that "password" through my shell script.

    Does any body knows, if it is possible?? if yes then how ??

  6. #6
    Linux Newbie
    Join Date
    Feb 2009
    Posts
    99
    you have to edit /etc/sudoer file
    exmaple:
    username ALL=(ALL) NOPASSWD: /sbin/mount /dev/cdrom /mnt

    so your script can be write to:
    #!/bin/bash
    sudo /sbin/mount /dev/cdrom /mnt

    and must be execute by username < - user.

  7. #7
    Just Joined!
    Join Date
    Apr 2008
    Posts
    4
    I want to write more scripts like this which asks for the different things from user.

    and I want to make in that way it will do everything and automatically from the shell script.

  8. #8
    Linux Newbie
    Join Date
    Feb 2009
    Posts
    99
    try chown root script.sh ; chmod 1555 script.sh <- but dangerous.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...