求助:deepin linux 如何设置某个程序始终以管理员身份运行?
Tofloor
poster avatar
89******81@qq.com
deepin
2018-01-16 19:11
Author
我使用APiCloudstudio2,但是这个软件需要管理员权限读写文件,我已经将软件目录设置为chown root:root 了,但是貌似还是不行,在命令行里面,用root用户打开程序就可以正常使用!

想指导如何一直用root用户权限去打开,不用命令行,直接点击应用图标就可以,最好是可以配置desktop文件,直接以管理员权限运行。求大神指导!我是Linux新手,谢谢!
Reply Favorite View the author
All Replies
wangyong
deepin
2018-01-16 19:31
#1
在desktop文件的exec哪一行等号后面加上pkexec 就行了
Reply View the author
89******81@qq.com
deepin
2018-01-17 00:16
#2
https://bbs.deepin.org/post/151900
在desktop文件的exec哪一行等号后面加上pkexec 就行了

谢谢!找这个方法找了好久了,应该早点提出来的,不然也不用折腾这么久
Reply View the author
89******81@qq.com
deepin
2018-01-17 00:21
#3
https://bbs.deepin.org/post/151900
在desktop文件的exec哪一行等号后面加上pkexec 就行了

Exec=pkexec /opt/Apicloud-Studio/apicloud-studio-2/apicloud-studio-2

是这样么?还是路径要加‘或者其他的
Reply View the author
comzhong
deepin
2018-01-17 00:24
#4
本帖最后由 comzhong 于 2018-1-17 10:58 编辑

前面加 gksudo 也可以,比如:gksudo gedit
gksu  gedit
Reply View the author
iminto
deepin
2018-01-17 00:56
#5
  1. TryExec=su-to-root
  2. Exec=su-to-root -X -c xxx.sh
Copy the Code
Reply View the author
wangyong
deepin
2018-01-17 17:13
#6
https://bbs.deepin.org/post/151900
Exec=pkexec /opt/Apicloud-Studio/apicloud-studio-2/apicloud-studio-2

是这样么?还是路径要加‘或者 ...

我发现 gksu 加到命令行前面更好使, pkexec 有些程序还弹不出来
Reply View the author
Comments
lineme
2018-01-17 17:18
大多数都弹不出来:)
comzhong
deepin
2018-01-17 18:55
#7
本帖最后由 comzhong 于 2018-1-17 20:51 编辑

pkexec 要先添加配置文件[/quote]
提权配置文件(以深度格式化工具为例子):
com.deepin.pkexec.usb-device-formatter.policy

  1. "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
  2. "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">

  3.   LinuxDeepin
  4.   https://www.deepin.com/
  5.   
  6.     Authentication is required to run the Usb Device Formatter
  7.     usb-device-formatter
  8.    
  9.       no
  10.       no
  11.       yes 
  12.    
  13.     /usr/bin/usb-device-formatter 
  14.     true 
  15.   

Copy the Code


配置文件目录:
/usr/share/polkit-1/actions/

启动方式:
    $pkexec usb-device-formatter
Reply View the author
89******81@qq.com
deepin
2018-01-17 19:54
#8
https://bbs.deepin.org/post/151900
pkexec 要先添加配置文件,老王居然不知道么?

提权配置文件(以深度格式化工具为例子):

我前面使用pkexec 的时候的确不能弹出软件的界面,然后就删除了,也没有再折腾了,等下再试试加配置文件看能否正常运行吧
Reply View the author
89******81@qq.com
deepin
2018-01-17 19:56
#9
https://bbs.deepin.org/post/151900
我发现 gksu 加到命令行前面更好使, pkexec 有些程序还弹不出来

gksu 我加了之后只弹出了授权密码框,然后就没有反应了
Reply View the author
wangyong
deepin
2018-01-17 20:51
#10
https://bbs.deepin.org/post/151900
gksu 我加了之后只弹出了授权密码框,然后就没有反应了

你先在终端中加上 pkexec/gksu 以后,后面跟desktop文件的 exec 内容,如果终端能够启动,desktop 文件的方式一定可以启动,如果终端都报错,你也可以进一步分析。
Reply View the author
蒙笛
deepin
2018-01-18 03:34
#11
这个功能将来会不会加到启动器右键菜单里?那样比较方便。
Reply View the author
comzhong
deepin
2018-01-18 05:22
#12
本帖最后由 comzhong 于 2018-1-17 21:25 编辑
https://bbs.deepin.org/post/151900
我前面使用pkexec 的时候的确不能弹出软件的界面,然后就删除了,也没有再折腾了,等下再试试加配置文件 ...

以 gedit 为例:

1.在 /usr/share/polkit-1/actions 添加 org.gnome.gedit.policy

需要修改的地方为:7、10、11、12、17、20、21 行

  1. "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
  2. "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">


  3.   org.gnome.gedit
  4.   https://www.deepin.com/

  5.   
  6.     Authentication is required to run the gedit
  7.     gedit 需要进行身份验证

  8.    
  9.       no
  10.       no
  11.       auth_admin
  12.    

  13.     /usr/bin/gedit
  14.     true
  15.   

Copy the Code


2. 在 /usr/share/applications  复制一份 文字編輯器,粘贴,改名为 文字編輯器admin,以管理员权限编辑内容,找到所有有 "Exec=" 的行,添加为 "Exec=pkexec "。


Exec=gedit %U
改为:
Exec=pkexec gedit %U

3.在启动器中启动 文字編輯器admin ,弹出授权对话框,不要授权对话框,配置中改为:yes
Reply View the author
89******81@qq.com
deepin
2018-01-18 19:09
#13
https://bbs.deepin.org/post/151900
以 gedit 为例:

1.在 /usr/share/polkit-1/actions 添加 org.gnome.gedit.policy

谢谢!非常感谢耐心解答,已经收藏!
Reply View the author
89******81@qq.com
deepin
2018-01-30 04:52
#14
https://bbs.deepin.org/post/151900
以 gedit 为例:

1.在 /usr/share/polkit-1/actions 添加 org.gnome.gedit.policy

admin_keep是什么意思?是保持root权限么?
Reply View the author
89******81@qq.com
deepin
2018-01-30 04:57
#15

  1. "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
  2. "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">


  3.   org.gnome.gedit
  4.   https://www.deepin.com/

  5.   
  6.     Authentication is required to run the gedit
  7.     Apicloud-studio-2需要root权限

  8.    
  9.       no
  10.       no
  11.       yes
  12.    

  13.     /opt/apicloud-studio-2/apicloud-studio-2
  14.     true
  15.   

Copy the Code
最后那个%u好像没有什么效果,不知道是什么用法。
Reply View the author
comzhong
deepin
2018-01-30 05:16
#16
xxc_00126 发表于 2018-1-29 20:52
admin_keep是什么意思?是保持root权限么?

权限保持,好像默认是保持5分钟,5分钟内不需要再次输入密码
Reply View the author
comzhong
deepin
2018-01-30 05:26
#17
https://bbs.deepin.org/post/151900
最后那个%u好像没有什么效果,不知道是什么用法。

%U是linux下.desktop文件中Exec关键字的一个形式参数,用来描述如何处理可执行程序的实际输入参数:

  1. %u 代表一个URL。也可以是一个本地文件路径。

  2. %U 代表一系列URL,其中每一个URL作为一个单独的参数传递给可执行程序。也可以是一系列本地文件路径。
Copy the Code


例如 /usr/share/applications/gedit.desktop 文件中包含:
  1. Exec=gedit %U
Copy the Code


这表示gedit的参数将被视为一系列URL(或者文件路径)。
Reply View the author
89******81@qq.com
deepin
2018-02-01 19:04
#18
https://bbs.deepin.org/post/151900
%U是linux下.desktop文件中Exec关键字的一个形式参数,用来描述如何处理可执行程序的实际输入参数:

非常感谢!不积跬步无以至千里!
Reply View the author
scruom
deepin
2018-04-30 01:39
#19
非常感谢这个帖子的所有回答的朋友,现在配置好了,点击程序图标,弹出root密码框,输入密码就可以启动了,但是每次打开都要输入密码,感觉有点麻烦,不知道该怎么解决了。
Reply View the author
shenyue
deepin
2018-06-26 19:04
#20
我添加上 pkexec 后,启动软件,输入密码之后,就没有反应了。

文件:
[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=pkexec /usr/share/code/code --unity-launch %F
Icon=code
Type=Application
StartupNotify=true
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;
Actions=new-empty-window;
Keywords=vscode;

X-Desktop-File-Install-Version=0.23

[Desktop Action new-empty-window]
Name=New Empty Window
Exec=pkexec /usr/share/code/code --new-window %F
Icon=code


Reply View the author