ith*_*rld 8 python macos firewall certificate
当我在Mac上运行python应用程序时,它显示了许多有关希望“ Python.app”接受传入网络连接的对话框。
即使我允许多次,它也会一次又一次地显示。
如何让它一次又不显示呢?
我发现了这个问题: 将Python添加到OS X防火墙选项吗?
我按照公认的答案去做,但是最后我跑步codesign -s "My Signing Identity" -f $(which python)时说:
/usr/bin/python: replacing existing signature
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: can't create output file: /usr/bin/python.cstemp (Operation not permitted)
/usr/bin/python: the codesign_allocate helper tool cannot be found or used
Run Code Online (Sandbox Code Playgroud)
下一步怎么办?
小智 5
我从 python.org 安装了 Python 3.6,我遇到了类似的问题。我反复尝试对 python 二进制文件 /usr/local/bin/python3、/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 等进行自签名,但我会继续获得 MacOS 防火墙拒绝/允许弹出。
最后,自签名位于 /Library/Frameworks/Python.framework/Versions/3.6/Resources 的应用程序成功了:
codesign --force --sign "My Signing Identity" /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app
Run Code Online (Sandbox Code Playgroud)
我在 MacOS Mojave 10.14.1 上是为了它的价值。
With the OS X firewall enabled, you can remove the "Do you want the application "python" to accept incoming network connections?" message.
Create a self-signed certificate.
Open Keychain Access. Applications > Utilities > Keychain Access.
Keychain Access menu > Certificate Assistant > Create a Certificate...
Enter a Name like "My Certificate".
Select Identity Type: Self Signed Root
Select Certificate Type: Code Signing
Check the Let me override defaults box
Click Continue
Enter a unique Serial Number
Enter 7300 for Validity Period.
Click Continue
Click Continue for the rest of the dialogs
Now sign your application
codesign -s "My Certificate" -f $(which python)
In the dialog that appears, click "Allow".
Note that when using a virtual environment, you need to activate the virtual environment before running this command.
Run Code Online (Sandbox Code Playgroud)
显然,El Capitan 有一种称为系统完整性保护的功能,可以防止任何用户(甚至 root)修改某些操作系统资源。例如本例中的 /usr/bin 目录,其中包含 python 可执行文件。要对 python 二进制文件进行自签名,您可以通过在恢复模式下重新启动 Mac(按住 CMD+R 的同时重新启动)来禁用 SIP,然后在终端中输入以下内容:
csrutil disable
然后启动回常规 OSX,并按照以下步骤对 python 进行自签名并执行:
codesign -s "My Signing Identity" -f $(which python)
最后重新启动回到恢复模式,并重新启用 SIP:
csrutil enable
| 归档时间: |
|
| 查看次数: |
5298 次 |
| 最近记录: |