View Full Version : in a shell script: change for one command to root
christoph
2003-09-24, 08:09 AM CDT
Hi
In a shell script I want to do some stuff. One of the commands need to
be done as root. Is there any way of asking the user for the root
password, then execute "this" next command as su and go back to the
normal user?
many thanks for some examples/hints
cheers!
christoph
Mauriat
2003-09-24, 10:47 AM CDT
christoph wrote:
> Hi
> In a shell script I want to do some stuff. One of the commands need to
> be done as root. Is there any way of asking the user for the root
> password, then execute "this" next command as su and go back to the
> normal user?
>
> many thanks for some examples/hints
>
> cheers!
> christoph
man sudo
--
Mauriat
----------------------------
Remove 'NOSPAM' to email me.
Matt H
2003-09-25, 08:15 AM CDT
On Wed, 24 Sep 2003 07:09:10 -0700, christoph wrote:
> Hi
> In a shell script I want to do some stuff. One of the commands need to
> be done as root. Is there any way of asking the user for the root
> password, then execute "this" next command as su and go back to the
> normal user?
#!/bin/sh
echo "Doing some work..."
echo "Doing more work..."
su -c "echo Running as root" # su will prompt for password
echo "Back to more work..."
jeem
2003-09-25, 07:09 PM CDT
Matt H wrote:
> On Wed, 24 Sep 2003 07:09:10 -0700, christoph wrote:
>
>
>>Hi
>>In a shell script I want to do some stuff. One of the commands need to
>>be done as root. Is there any way of asking the user for the root
>>password, then execute "this" next command as su and go back to the
>>normal user?
>
>
> #!/bin/sh
>
> echo "Doing some work..."
> echo "Doing more work..."
> su -c "echo Running as root" # su will prompt for password
> echo "Back to more work..."
>
It's possible to set the suid bit as root. Look into suid. For example
the passwd command is suid.
Matt H
2003-09-25, 10:30 PM CDT
On Fri, 26 Sep 2003 01:09:27 +0000, jeem wrote:
> It's possible to set the suid bit as root. Look into suid. For example
> the passwd command is suid.
suid scripts will never work in Linux.
jeem
2003-09-25, 10:43 PM CDT
Matt H wrote:
> On Fri, 26 Sep 2003 01:09:27 +0000, jeem wrote:
>
>
>>It's possible to set the suid bit as root. Look into suid. For example
>>the passwd command is suid.
>
>
> suid scripts will never work in Linux.
I have been reading a security book for Unix. I have to keep reminding
myself Unix and Linux are different in many ways. Does Linux have some
other way to say run the passwd command. Here is what it is on my Linux
Box. -r-s--x--x . I assumed it was suid???
Matt H
2003-09-26, 08:05 AM CDT
On Fri, 26 Sep 2003 04:43:16 +0000, jeem wrote:
> I have been reading a security book for Unix. I have to keep reminding
> myself Unix and Linux are different in many ways. Does Linux have some
> other way to say run the passwd command. Here is what it is on my Linux
> Box. -r-s--x--x . I assumed it was suid???
Are you asking how to run the passwd command from a script? Just use the
command 'passwd'. Linux does support the SUID bit on executables, but not
on scripts.
vBulletin® v3.8.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.