ping method from net-ping without root on Linux?
This is probably a Linux problem and not a Ruby problem, but the way I would solve this for a binary on Linux is not how I would want to solve if for a single Ruby file.
If I try to run a ping from net-ping' (Net::Ping::ICMP.new(target).ping`), I get the error:
requires root privileges or setcap net_raw (StandardError)
I have my ping function in it's own Ruby file (ping.rb) that I want to call from a lower privilege Ruby application (main.rb).
setcapping cap_net_raw on the individual Ruby file doesn't seem to work, and I don't want to setcap Ruby in general (/usr/bin/ruby2.5).
I'm curious if anyone has solved the problem without having to just call the host ping binary directly.
13 comments · 76% upvoted · other discussions
Not ruby specific but I don’t believe there is any way to setcap on any script, it has to be done on the interpreter binary. You could use something like chruby to isolate an interpreter for this if you want.