我想使用以下命令启动 wireshark:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY wireshark
No protocol specified
** (wireshark:9323): WARNING **: Could not open X display
No protocol specified
error: XDG_RUNTIME_DIR not set in the environment.
(wireshark:9323): Gtk-WARNING **: cannot open display: :0
答案1
在中创建新的策略规则/usr/share/polkit-1/actions/
sudo nano /usr/share/polkit-1/actions/wireshark.policy
并添加以下几行:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<action id="org.freedesktop.policykit.pkexec.run-wireshark">
<description>Run FlashTool</description>
<message>Authentication is required to run Wireshark</message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>no</allow_inactive>
<allow_active>auth_admin_keep</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/wireshark</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">TRUE</annotate>
</action>
</policyconfig>
然后创建一个新脚本wireshark-pkexec
sudo nano /usr/bin/wireshark-pkexec
并添加以下几行:
#!/bin/sh
pkexec "wireshark" "$@"
并添加可执行标志
sudo chmod +x /usr/bin/wireshark-pkexec
最后创建一个新的桌面文件
nano /usr/share/applications/wireshark-pkexec.desktop
并添加以下几行:
[Desktop Entry]
Name=Wireshark as root
GenericName=Network Analyzer
Comment=Network traffic analyzer
Exec=wireshark-pkexec %f
Icon=wireshark
Terminal=false
Type=Application
Categories=GNOME;Network;
StartupNotify=true
MimeType=application/vnd.tcpdump.pcap;application/x-pcapng;application/x-snoop;application/x-iptrace;application/x-lanalyzer;application/x-nettl;application/x-radcom;application/x-etherpeek;application/x-visualnetworks;application/x-netinstobserver;application/x-5view;
重新启动 Unity/GNOME Shell 并启动Wireshark as root