zoukankan      html  css  js  c++  java
  • Ubuntu制作系统服务时服务程序需要root权限

    Ubuntu制作系统服务时服务程序需要root权限

    1、简单service

    start_service.service

    [Unit]
    Description=MonitorIP
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    WorkingDirectory=/home/up/docker-compose-test/test_demo/service_test
    ExecStart=/home/up/docker-compose-test/test_demo/service_test/start.sh
    Type=simple
    Restart=always
    TimeoutSec=infinity
    User=root
    
    [Install]
    WantedBy=multi-user.target
    

    2、服务程序需要root权限

    方案一(推荐)

    • 设置service文件中Userroot

    方案二(不推荐)

    • 设置service文件中User当前用户(非root)

      [Unit]
      Description=MonitorIP
      After=network-online.target
      Wants=network-online.target
      
      [Service]
      WorkingDirectory=/home/up/docker-compose-test/test_demo/service_test
      ExecStart=/home/up/docker-compose-test/test_demo/service_test/start.sh
      Type=simple
      Restart=always
      TimeoutSec=infinity
      User=up
      
      [Install]
      WantedBy=multi-user.target
      
    • 修改sudo时不需要输入密码

      • sudo vim /etc/sudoers

        sudo下一行添加your_username ALL = (ALL) NOPASSWORD: ALL

        #
        # 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:/snap/bin"
        
        # Host alias specification
        
        # User alias specification
        
        # Cmnd alias specification
        
        # User privilege specification
        root    ALL=(ALL:ALL) ALL
        
        # Members of the admin group may gain root privileges
        %admin ALL=(ALL) ALL
        
        # Allow members of group sudo to execute any command
        %sudo   ALL=(ALL:ALL) ALL
        up ALL=(ALL) NOPASSWD: ALL    # 例如这里添加up用户不输入密码
        # See sudoers(5) for more information on "#include" directives:
        
        #includedir /etc/sudoers.d
        
  • 相关阅读:
    基础知识梳理
    计算机基础
    IAR平台下使用STM32的DSP配置方法
    第五节:STM32输入捕获(用CubeMX学习STM32)
    第四节:定时器中断及定时器产生PWM(用CubeMX学习STM32)
    第三节: 串口通信(用CubeMX学习STM32)
    第二节: 外部中断学习(用CubeMX学习STM32)
    第一节补充: 按键操作(CubeMX加HAL库学STM32系列)
    第一节:用Cube学32之简单IO口操作(点灯及按键)
    STM32程序中使用printf打印中文字符乱码
  • 原文地址:https://www.cnblogs.com/linagcheng/p/14272945.html
Copyright © 2011-2022 走看看