Mac端安裝libimobiledevice
brew install libimobiledevice
用libimobiledevice提供的iproxy做本地端口轉(zhuǎn)發(fā)(本地端口2222映射到TCP端口22)
iproxy 2222 22
USB連接移動設(shè)備ssh登錄
ssh root@localhost -p 2222
每次登錄都需要這么做勉失,會很耗時、麻煩漓摩,因?yàn)榭梢宰龀赡_本,開機(jī)啟動時執(zhí)行
創(chuàng)建文件com.usbmux.iproxy.plist,放到目錄~/Library/LaunchAgents/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.usbmux.iproxy</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/iproxy</string>
<string>2222</string>
<string>22</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
然后運(yùn)行命令
launchctl load ~/Library/LaunchAgents/com.usbmux.iproxy.plist
重新打開終端就可以直接ssh root@localhost -p 2222
登錄
如果還嫌棄ssh root@localhost -p 2222
麻煩,可以創(chuàng)建配置一個config文件,如下,放到$HOME/.ssh/文件夾下
Host iPhone
Hostname localhost
User root
Port 2222
最后通過ssh iPhone
登錄