如何授予对用户应用程序的root访问权限?

编程入门 行业动态 更新时间:2024-10-14 06:21:32
本文介绍了如何授予对用户应用程序的root访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个在Linux移动设备上运行的用户级C ++测试应用程序.其中一项测试涉及启用/禁用打印机纸张传感器,这需要在设备文件上写入具有root权限.有没有办法向我的应用程序授予这种特权?如果没有,是否有解决方法?

I have a user-level C++ test application running on a linux mobile device. One of the test involves enabling/disabling printer paper sensor which requires root privileges writing on a device file. Is there a way to grant my application that kind of privilege? If none, is there a workaround for that?

推荐答案

可以做到

按root执行:

chown -v root:root /path/to/yourapp chmod -v 4755 /path/to/yourapp

或者

chmod -v u+s /path/to/yourapp

或者

man chmod

这将不适用于脚本.是的,您应该认真对待 jdizzle 所说的删除不必要的特权.

This will not work with scripts. And yes, you should take seriously what jdizzle said about dropping unnecessary privileges.

解决此问题的另一种方法是使运行该应用程序的用户成为拥有设备文件的组的成员.例如,

Another way to solve this is to make the user who runs the application a member of the group that owns the device file. For example,

ls -la /dev/devicefile crw-rw---- 1 root printer 4, 0 may 6 10:56 /dev/devicefile

组的

成员可以读写设备,因此您只需将joe添加到printer组(并重新启动会话).

members of the printer group can read and write to the device, so you just need to add joe to the printer group (and restart the session).

gpasswd -a joe printer

如果需要调整devicefile权限,则可能需要编辑udev规则以使其永久.但是chmod应该也可以.

If you need to adjust the devicefile permissions, you probably will need to edit udev rules to make it permanent. But chmod should work too.

其他值得研究的选项: setcap(8) (指南此处)和 sudo(8) .

Other options worth investigating: setcap(8) (nice guide here) and sudo(8).

更多推荐

如何授予对用户应用程序的root访问权限?

本文发布于:2023-11-17 08:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609524.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   访问权限   用户   root

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!