From: Michael Guterl Date: 2009-12-13T00:20:01+09:00 Subject: Re: How to make a ruby program tu run unser other user:group different than root On Sat, Dec 12, 2009 at 10:14 AM, IƱaki Baz Castillo wrote: > Hi, many daemons allow an argument "-u uid" which makes the program to run > under that user. Of course this can be done just by root or privileged users. > > It's commonly used in init scripts. These are started by init process running > as root and start services running under other user. > > However it seems that ruby binary doesn't implement such option. Is there any > way to get it? > If not I should use "su" command and so. > Here's a snippet from our unicorn config that changes the user for workers from root to deploy. You can probably use something from it. ## # Unicorn master is started as root, which is fine, but let's # drop the workers to deploy:deploy uid, gid = Process.euid, Process.egid user, group = 'deploy', 'deploy' target_uid = Etc.getpwnam(user).uid target_gid = Etc.getgrnam(group).gid worker.tmp.chown(target_uid, target_gid) if uid != target_uid || gid != target_gid Process.initgroups(user, target_gid) Process::GID.change_privilege(target_gid) Process::UID.change_privilege(target_uid) end Best regards, Michael Guterl