|
#1
| |||
| |||
|
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 |
|
#2
| ||||
| ||||
|
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 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!" |
|
#3
| ||||
| ||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | |
|
|