2024 年 macOS 上各家包管理器的现状

我认为日常用的软件必须从可信来源下载。一般的 macOS Application 不需要 sudo 也能安装,但是 GUI 下 macOS 是会验证有从可信来源的簽名才会放行的,如果软件被篡改,系统是能发现并阻止的,哪怕不是可信来源的软件,也有沙盒机制保㡳。在终端运行的程序,为了方便是很多人是关掉这个验证的,不然多次从 shell 运行同一个程序性能会严重降低,而且没有沙盒保护,所谓 GUI App 不需要 sudo 所以终端下用包管理器也不用 sudo 的理由站不住腳。pkgsrc 从下载 distrubution 时有 GPG key,软件也是测试后才放到仓库,安装单个包时也会 verifiy signature,用 sudo 安装包保证除非恶意软件有管理员权限,不然不会被篡改。而 brew 对在 path 变量里天天运行的程序不做任何权限上的保护,本身做为知名软件也没有做对自身完整性验证,有把常用命令替換成恶意软件的风险极大,我是很不放心的,相信题主也是有同样的担心

man pkg_add 的加粗段落,提醒用户小心木马,brew 就沒有这样的说明,安全意识不是一个级別的 brew 只提供软件的 SHA 而不是 GPG 签名,不能对软件的来源做保障,在 formula 没有权限保护时就更槽了。

Since the pkg_add command may execute scripts or programs contained within a package file, your system may be susceptible to “Trojan horses” or other subtle attacks from miscreants who create dangerous package files.

You are advised to verify the competence and identity of those who provide installable package files. For extra protection, use the digital signatures provided where possible (see the pkg_install.conf(5)), or, failing that, use tar(1) to extract the package file, and inspect its contents and scripts to ensure it poses no danger to your system’s integrity. Pay particular attention to any +INSTALL or +DEINSTALL files, and inspect the +CONTENTS file for @cwd, @mode (check for setuid), @dirrm, @exec, and @unexec directives, and/or use the pkg_info(1) command to examine the package file.

4 个赞