What user is a Ruby process running as?

I have a script that shouldn't be run as anybody other than the "nobody" user if it's in production mode, since it will overwrite files with the wrong permissions otherwise. My colleague Ben Tucker alerted me to Process.uid, which allows me to do something like
$ /home/ian/sw/bin/ruby -e "puts Process.uid == `id -u nobody`"
false
$ sudo -u nobody /home/ian/sw/bin/ruby -e "puts Process.uid == `id -u nobody`"
true
The rest should be trivial.

Leave a Reply