如何授予对用户应用程序的root访问权限? [英] How do I grant root access to a user application?

查看:230
本文介绍了如何授予对用户应用程序的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访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆