ubuntu18.04 tcpdump 权限问题

在新装的ubuntu ubuntu18.04上使用tcpdump的命令进行抓包并保存致本地文件,当使用命令sudo tcpdump -i ens160 -w http.pcap 的时候,出现错误:

tcpdump:  Permission denied

本地帐户是有sudo权限的,而且该账户不使用sudo权限能够在该目录创建文件,并没有报错,为何sudo 权限反倒 Permission Denied?

自然,这个问题最好只能是tcpdump出了问题,google 了一下,发现这是Ubuntu系统下的权限管理framework  “AppArmor” 中设置了tcpdump 工作在enforce模式,
其不能正常工作于是报错:

$ sudo apparmor_status
apparmor module is loaded.
10 profiles are loaded.
10 profiles are in enforce mode.
   /sbin/dhclient3
   /usr/bin/evince
   /usr/bin/evince-previewer
   /usr/bin/evince-thumbnailer
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/connman/scripts/dhclient-script
   /usr/lib/cups/backend/cups-pdf
   /usr/sbin/cupsd
   /usr/sbin/tcpdump
   /usr/share/gdm/guest-session/Xsession
0 profiles are in complain mode.
1 processes have profiles defined.
1 processes are in enforce mode :
   /usr/sbin/cupsd (1240)
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.

tcpdump不能工作在enforce模式下,于是改为使用complain模式:

$ sudo aa-complain tcpdump
Setting /etc/apparmor.d/usr.sbin.tcpdump to complain mode.

$ sudo apparmor_status
apparmor module is loaded.
10 profiles are loaded.
9 profiles are in enforce mode.
   /sbin/dhclient3
   /usr/bin/evince
   /usr/bin/evince-previewer
   /usr/bin/evince-thumbnailer
   /usr/lib/NetworkManager/nm-dhcp-client.action
   /usr/lib/connman/scripts/dhclient-script
   /usr/lib/cups/backend/cups-pdf
   /usr/sbin/cupsd
   /usr/share/gdm/guest-session/Xsession
1 profiles are in complain mode.
   /usr/sbin/tcpdump
1 processes have profiles defined.
1 processes are in enforce mode :
   /usr/sbin/cupsd (1240)
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.

注意机器重启后, 设置的TCPDUMP 为complain模式会失效。需要重新设置tcpdump为complain模式。
第二次不能直接使用udo aa-complain tcpdump,设置。 命令会提示错误。而需要使用下面的命令重新设置。
aa-complain /etc/apparmor.d/usr.bin.tcpdump

 

你可能感兴趣的:(Linux)