11

MacOS 10.12.5关闭SIP,升级自带的openssl

 3 years ago
source link: https://chegva.com/3185.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

MacOS 10.12.5关闭SIP,升级自带的openssl

由于Mac自带的 openssl 太老了,安装python扩展包报错,需要升级到高版本。

一、安装openssl

查看当前的openssl 的版本和目录:

➜  ~ openssl version && which openssl
OpenSSL 0.9.8zh 14 Jan 2016

升级openssl

brew update
brew upgrade openssl
...
Warning: openssl 1.0.2q is already installed and up-to-date
To reinstall 1.0.2q, run `brew reinstall openssl`

brew reinstall openssl #重新安装

查看安装后信息:

➜  ~ brew list openssl
/usr/local/Cellar/openssl/1.0.2q/.bottle/etc/ (8 files)
/usr/local/Cellar/openssl/1.0.2q/bin/c_rehash
/usr/local/Cellar/openssl/1.0.2q/bin/openssl
/usr/local/Cellar/openssl/1.0.2q/include/openssl/ (75 files)
/usr/local/Cellar/openssl/1.0.2q/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2q/lib/libssl.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2q/lib/engines/ (12 files)
/usr/local/Cellar/openssl/1.0.2q/lib/pkgconfig/ (3 files)
/usr/local/Cellar/openssl/1.0.2q/lib/ (4 other files)
/usr/local/Cellar/openssl/1.0.2q/share/man/ (1682 files)

成功安装到/usr/local/Cellar/openssl/1.0.2q

二、关闭SIP,更换旧的openssl链接

将homebrew下载的openssl软链接/usr/bin/openssl目录下。先备份然后做软链。

$ mv /usr/bin/openssl /usr/bin/openssl_old
mv: rename /usr/bin/openssl to /usr/bin/openssl_old: Operation not permitted
$ ln -s /usr/local/Cellar/openssl/1.0.2q/bin/openssl /usr/bin/openssl
ln: /usr/bin/openssl: Operation not permitted

Operation not permitted提示没有权限操作,网上搜索说需要关闭SIP。先来看看这是个啥玩意。

系统集成保护(System Integrity Protection,SIP),为了防止恶意篡改系统内核程序而设置的一种内核保护机制。即使是root用户也有一些目录是无法修改的,比如:

  • /System

  • /sbin

  • /usr (except /usr/local)

对于开发者来说,总是需要安装很多的模块,有的时候就会触及到这个禁区,因此可以手动关闭这个功能,当然同时也带来了系统的漏洞,是用的时候需要多加注意。

直接开干,网上很多都是针对10.12版本以下来讲的,10.12关闭方法不一样了。方法如下:

1.开机按住command+r键,进入恢复模式
2.进入后打开实用工具--终端
3.输入命令csrutil disable关闭SIP。 (同样的步骤输入命令csrutil enable,即可重新打开SIP)
4.关闭重启进入系统即可
10.12版本已经无法通过按住command+R进入恢复模式,经过百度和google发现网上的解决方法均是重启电脑,选择使用工具里的终端,输入命令行,但是这只在10.11的版本有用。
现在分享解决方法。
1.关闭计算机
2.在计算机关闭后按住shift+control+option+开机键(16年的mbp则为指纹识别键)两秒
3.按开机键开机(16年的mbp则为指纹识别键),按住command+R进入recovery界面,再查看顶部的菜单栏,发现工具栏中原本消失的几个选项出现了
4.点击实用工具,打开终端,输入:csrutil disable   重启mac,输入: csrutil status 
看到  System Integrity Protection status: disabled.  成功关闭sip

这里注意要关机的是关机时要按一起看那几个键几秒,然后开机时一起cmd+r按着不松,直到出现可选择的界面然后就可以操作了,直接打开终端输入关闭命令,然后重启

$ csrutil disable
$ csrutil status
$ reboot

更改openssl软链。

➜  ~ sudo mv /usr/bin/openssl /usr/bin/openssl_old
➜  ~ sudo ln -s /usr/local/Cellar/openssl/1.0.2q/bin/openssl /usr/bin/openssl
➜  ~ openssl version
OpenSSL 1.0.2q  20 Nov 2018

搞定了,安装完所需扩展后,为了安全一定要重新开启csrutil,所以得重新来一次,坑!

➜  ~ csrutil enable
➜  ~ csrutil status
➜  ~ reboot

参考:

anzhihe安志合个人博客,版权所有丨 如未注明,均为原创 丨转载请注明转自:https://chegva.com/3185.html | ☆★★每天进步一点点,加油!★★☆

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK