需要sudo权限的exec程序

时间:2014-10-22 14:48:14

标签: c++ linux debian exec sudo

所以我的最终目标是在启动时在我的Beaglebone Black上运行一个程序(将其添加到init文件中),该程序将执行其他程序。正在启动的其他程序需要sudo权限才能启动。从研究来看,我已经看到了几种方法可以做到这一点,但我不知道哪一种方法是正确的"。有人能指出我正确的方向吗?

这是我正在测试的代码,用于启动众多程序之一:

#include <iostream>
#include <unistd.h>

using std::cout;
using std::cin;

int main()
{
   pid_t pid;

   pid = fork();

   if (0 == pid)
   {
      setreuid(geteuid(), getuid());
      execl("/usr/local/bin/osmo-trx", "osmo-trx", "-f", NULL);
      cout << "\n\n***Something went wrong starting osmo-trx***\n\n";
   }
   else if (0 < pid) ;
   else
   {
      cout << "\n\nSomething went wrong...\n\n";
      return -1;
   }

   return 0;
}

我无法弄清楚正确的问题。以下是我所拥有的一些内容,尽管它们可能会偏离我应该走的道路。

  1. 我可以用sudo权限执行程序吗?试过the uid但没有运气。

  2. 如果我给de​​bian用户root权限,我能运行任何程序吗?试图editing my visudo并添加debian但没有成功。以下是文件:

    #
    # This file MUST be edited with the 'visudo' command as root.
    #
    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.
    #
    # See the man page for details on how to write a sudoers file.
    #
    Defaults        env_reset
    Defaults        mail_badpass
    Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    
    # Host alias specification
    
    # User alias specification
    
    # Cmnd alias specification
    
    # User privilege specification
    root    ALL=(ALL:ALL) ALL
    debian  ALL=(ALL:ALL) ALL
    
    # Allow members of group sudo to execute any command
    %sudo   ALL=(ALL:ALL) ALL
    
    # See sudoers(5) for more information on "#include" directives:
    
    #includedir /etc/sudoers.d
    %admin  ALL=(ALL) ALL</code>
    

    - 注意:对于史诗缩进感到抱歉,但编辑在给我突出显示代码时遇到了麻烦.--

  3. 请帮忙......

0 个答案:

没有答案
相关问题