【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地址

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值