解决tcpdump sudo权限下Permission denied

在新装的ubuntu server上脚本调用了tcpdump的命令进行抓包并保存致本地文件,当使用命令sudo tcpdump -i eth3 -w eth3_dump.pcap 的时候,出现错误:

$ sudo tcpdump -i eth3 -s 0 -w test_eth3.pcap

tcpdump: test_eth3.pcap: 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.


$ sudo vim /sys/kernel/security/apparmor/profiles

/usr/bin/evince-thumbnailer (enforce)
/usr/bin/evince-previewer (enforce)
/usr/sbin/tcpdump (enforce)
/usr/bin/evince (enforce)
/usr/sbin/cupsd (enforce)
/usr/lib/cups/backend/cups-pdf (enforce)
/usr/lib/connman/scripts/dhclient-script (enforce)
/usr/lib/NetworkManager/nm-dhcp-client.action (enforce)
/sbin/dhclient3 (enforce)
/usr/share/gdm/guest-session/Xsession (enforce)

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 sudo权限下Permission denied)