Discussion Locked

How to SU - in a script with password ?

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How do I "su - username" within a shell script and pass the username's password to complete the su?

For example, I am Bob and I want to give Jack a script that will su - Bob so he or anyone can cancel my print jobs.

My script should:

Enter Printer Name:
read printer
then I need to su - bob
cancel -a $printer
then end su and exit script

But the script will break to ask for bob's password.

I do not have root access therefore can not su - root in the script.

So to re-cap I want to write scripts that users can use that will allow them to become me temporarily to run or cancel jobs as me.

7 replies

by nikki96

AFAIK, you can't use SU this way. It is a security risk. Admins of secure systems would never allow it.
However, you can make a program, as yourself, with a setuid bit so that anyone running it runs it as you. That can be dangerous, security-wise, and if you aren't the admin of this system, you'd have to clear it with them. Many systems (including ours) do not allow shell scripts to have the setuid bit on - it has to be a C executable. Ask your sysadmin if that is the case for you.

Here's anice explanation of setuid with chmod. Remove any spaces in the pasted URL.
http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Setuid/lecture.html

by alveden

nikki96 is right bout how su should be used.

You can consider using sudo. sudo is a alternative for su. It can be configured to allow Jack to execute the kill print job script as Bob, without compromising any additional access to Jack.

Check out this link. Note: Only root can configure sudo.
http://www.courtesan.com/sudo/

by dbs

You can use an expect script to do this.

Expect your system admin to chastize you severely when he or she finds out about it.

The file will need to be readable by Frank, so there is nothing to keep him from seeing your password.

This discussion is closed to new replies.