问题:
对于通过代理访问内网服务器,我们需要通过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地址
Host de65
Hostname 192.168.3.65
User root
Port 22
ProxyCommand /usr/local/bin/corkscrew xxx.xx.95.236 9001 %h %p
Host de66
Hostname 192.168.3.66
User root
Port 22
ProxyCommand /usr/local/bin/corkscrew xxx.xx.95.236 9001 %h %p