【Mac】Mac終端下使用Corkscrew + SSH通過代理連接內網服務器

問題:

對於通過代理訪問內網服務器,我們需要通過http代理訪問代理服務器,再訪問內網服務器。而mac不支持xshell從而無法爲SSH連接增加代理,所以選擇corkscrew工具。

解決步驟:

1、通過Homebrew包管理工具(Homebrew的安裝和使用見鏈接)安裝corscrew

brew install corkscew
# 無需sudo

2、修改~/.ssh/config 配置文件(沒有則添加該文件)

1、How Is It Used?
---------------
#Setting up Corkscrew with SSH/OpenSSH is very simple.  Adding
#the following line to your ~/.ssh/config file will usually do
#the trick (replace proxy.example.com and 8080 with correct values):

ProxyCommand /usr/local/bin/corkscrew proxy.example.com 8080 %h %p


2、How Do I Use The HTTP Authentication Feature?
---------------------------------------------
#You will need to create a file that contains your usename and password
#in the form of : 
username:password

#I suggest you place this file in your ~/.ssh directory.

#After creating this file you will need to ensure that the proper perms
#are set so nobody else can get your username and password by reading
#this file.  So do this :
chmod 600 myauth

#Now you will have to change the ProxyCommand line in your ~/.ssh/config
#file.  Here's an example :

ProxyCommand /usr/local/bin/corkscrew proxy.work.com 80 %h %p ~/.ssh/myauth

3、重啓ssh服務(mac沒有service指令,使用如下指令)

# 啓動ssh服務(Mac默認情況下不會開機自啓ssh服務)
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

# 查看ssh服務狀態,出現 “- 0 com.openssh.sshd” 則啓動成功
sudo launchctl list | grep ssh

# 關閉ssh服務
sudo launchctl unload -w /System/Library/LaunchDaemons/ssh.plist

4、最後使用SSH命令連接目標服務器即可

sudo ssh <username>@<serverIP>
# username爲連接服務器的用戶名,serverIP爲請求連接的服務器內網IP地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章