我读过 Jay Lacroix 的关于“Mastering Ubuntu Server”的书,他建议删除所有不必要的软件包以减少攻击面。具体来说,他建议运行apt-cache rdepends <package>
以查明是否还有其他软件包取决于我们考虑删除的软件包。
我编写了一个 bash 脚本,列出了所有已安装包的依赖包,但需要很长时间(在 Raspberry Pi 4、8GB 上超过 30 分钟),我想知道是否有更好、更快的解决方案。
#!/bin/bash
readarray -t packages < <(dpkg --get-selections | cut -f1)
for package in ${packages[@]};
do
readarray -t dependents < <(apt-cache rdepends $package | sed -n '3,$s/^\s*//p')
echo "-----------------------------------------------------------------------" | tee -a packages_and_depents.txt
echo "${package} has these dependents on the system of max ${#dependents[@]}:" | tee -a packages_and_depents.txt
echo "-----------------------------------------------------------------------" | tee -a packages_and_depents.txt
for dependent in ${dependents[@]};
do
dpkg --get-selections $dependent …
Run Code Online (Sandbox Code Playgroud)