Mac终端下使用Corkscrew + SSH通过代理连接内网服务器

安装 corkscew

brew install corkscew

修改~/.ssh/config 配置文件(没有则添加该文件)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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

重启ssh服务(mac没有service指令,使用如下指令)

1
2
3
4
5
6
7
8
# 启动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

最后使用SSH命令连接目标服务器即可

1
2
sudo ssh <username>@<serverIP>
# username为连接服务器的用户名,serverIP为请求连接的服务器内网IP地址