image
image

Go Back   macosx.com > Mac Help Forums > Unix & X11

Reply
 
LinkBack Thread Tools
  #1  
Old March 14th, 2005, 06:35 PM
Registered User
 
Join Date: Mar 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
kxtrm is on a distinguished road
Unhappy Commands in Bash

im trying to run a sequence of commands from a bin/bash but what i need is log me as a different user and i use something like this


#!/bin/sh

su postgres
postgres
postmaster -D /usr/local/pgsql/data -i


But obviously doesn't work because of the password any suggestions to do this, as you can see im trying to start postgresql
Reply With Quote
  #2  
Old March 14th, 2005, 09:40 PM
davidbrit2's Avatar
Licensed Computer Geek
 
Join Date: Sep 2000
Location: Michigan, USA
Posts: 787
Thanks: 0
Thanked 0 Times in 0 Posts
davidbrit2 is on a distinguished road
SetUID bit to the rescue! Assuming you have a whole script that you want to execute as the user "postgres", this is actually painfully easy, as it turns out. Now, keep in mind that there's a minor security risk involved, as anybody with execute permission to the script file will be able to launch it with the privileges of the file's owner, in this case "postgres". But you'll be setting it to only allow certain users. That being said, you just need to use chmod and chown:

Code:
sudo chmod 4750 scriptfilename
sudo chown postgres:admin scriptfilename
The chmod command does a few things here. The 4 tells it to turn on the SetUID bit, meaning if anybody executes the file, it's run with the user ID of the file's owner. The 7 allows the owner "postgres" to have read, write, and execute permission. The 5 allows the "admin" group, which presumably includes your personal admin account, to read and execute the file. The 0 disallows everyone else from doing anything with the file.

And by using chown, you set the file's owner and group appropriately so it all works as expected. Make sense? This works with any executable on the system, and I do it fairly often for things like tcpdump and other diagnostic tools. You can set the owner of the program to "root", set the group to "admin", and change the permission bits to 4750 to allow everyone in the "admin" group access to the program with root privileges. It's extremely convenient if you know how to use it sensibly, and cuts down on a large amount of sudo use. Heh.
__________________
You can have my iBook when you pry it from my cold, dead fingers.
iBook - The computer of choice for the enlightened CS major. Come on Apple, let me do a commercial. ;-)
"An alloc a day keeps the DRAM away!"
Reply With Quote
  #3  
Old March 14th, 2005, 11:26 PM
mkwan's Avatar
Tech
 
Join Date: Aug 2001
Location: Canada
Posts: 241
Thanks: 0
Thanked 0 Times in 0 Posts
mkwan is on a distinguished road
very cool
__________________
mkwan

UNIX was created in the late 1960s, in an effort to provide a multiuser, multitasking system for use by programmers. The philosophy behind the design of UNIX was to provide simple, yet powerful utilities that could be pieced together in a flexible manner to perform a wide variety of tasks.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 08:04 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
Copyright 2000-2010 DigitalCrowd, Inc.