如何 运行 sudo 就像使用 RVM 一样

How to run sudo things as when using RVM

我正在我的机器上测试一个名为 packetgen 的库。问题不在于图书馆本身;我试图在我的网络上注入一个数据包只是为了进行简单测试。但是,当我注入它时,它会引发错误:

Traceback (most recent call last):
    3: from packet.rb:5:in `<main>'
    2: from /home/COM-COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib   /packetgen/packet.rb:240:in `to_w'
    1: from /home/COM-COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib/ packetgen/header/eth.rb:95:in `to_w'
/home/COM_COM/.rvm/gems/ruby-2.5.1/gems/packetgen-2.8.6/lib/packetgen /header/eth.rb:95:in `open_live': wlp2s0: You don't have permission to capture on that device (socket: Operation not permitted) (RuntimeError)

我需要超级用户权限才能在网络上捕获或注入数据包,但是如果我 运行 sudo 'ruby packet.rb' 它会引发一个不同的错误,因为 packetgen 没有安装在我的机器上ruby 的版本。我正在 运行 宁一个 ruby 版本不同于我的机器的预装版本礼貌 RVM (Ruby 版本管理器)。有没有人有解决方法或方法来 运行 这个程序而不用 sudo?谢谢!

RVM 具有 sudo 集成,请参阅 here

By default, when you use sudo your current shell environment is not passed through to the session created by it, but RVM already allows for easier access to sudo calls with rvmsudo. However, sudo's defaults are very strict and you might end up getting password prompts on commands that are set to use the sudo NOPASSWD directive.