用 sudo 執行 wireshark 遇到的問題

$ sudo wireshark
[sudo] password for xxxxxx: 
Invalid MIT-MAGIC-COOKIE-1 keyqt.qpa.xcb: could not connect to display :1
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.

Aborted

遇到上面的錯誤無法執行 wireshark ,輸入下列指令就可以正常執行 wireshark

$ xhost +local:1
non-network local connections being added to access control list
$ sudo wireshark
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'

或是可以設定權限給其他使用者,例如:

$ sudo setcap cap_net_raw,cap_net_admin+eip /usr/bin/dumpcap
$ sudo groupadd -s wireshark
$ sudo gpasswd -a $USER wireshark

詳細請參考:CapturePrivileges