🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.comp.hacker
Article #13355

在Linux环境中建立SSH tunnel

#13355
From: RSS Feed For GFW Blog
Date: Tue, 29 Sep 2009 15:17
70 lines
6667 bytes
来源:[http://www.log32.com/?p=856][1]

   [1]: http://www.log32.com/?p=856

本方法主要是参考了Johnathan的文章《[在 Linux 下使用你的网站主机作为加密代理服务器][2]》以及未知作者的文章《[一劳永逸的翻墙方式 ssh -D][3]》中的"Linux+Firefox"部分,此处去掉了技术细节,纯粹描述操作步骤。

   [2]: http://sprayfly.com/2009/07/05/%e5%9c%a8-linux-%e4%b8%8b%e4%bd%bf%e7%94%a8%e4%bd%a0%e7%9a%84%e7%bd%91%e7%ab%99%e4%b8%bb%e6%9c%ba%e4%bd%9c%e4%b
8%ba%e5%8a%a0%e5%af%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8/ (Permanent Link to 在 Linux 下使用你的网站主机作为加密代理服务器)

   [3]: http://digg.com/d1nsDv

 1,获得一个地处功夫网以外的主机上的SSH账号(我只介绍我的做法):

  我用的是Dreamhost的虚拟主机,一年¥49.9。进入主机设置页面,点击"manage users",在希望使用的用户名后面点击"edit",把"User account type"设置成"Shell account",向下拉页面,填入希望使用的账户密码,保存。

 2,生成SSH密钥并上传:

打开本地控制台(本段以下操作如非注明都是在控制台中),输入


    ssh-keygen -t rsa

然后一路回车,中间提示设置密码,不要填写。

会在/home/(当前用户名)/.ssh 目录中生成id_rsa和id_rsa.pub两个文件。

进入这两个文件所在的目录,输入


    chmod 700 id_rsa


    mv id_rsa.pub authorized_keys


    chmod 700 authorized_keys

打开一个FTP工具,进入墙外主机的根目录,建立一个文件夹".ssh",把authorized_keys上传到这个文件夹中。

 3,下载脚本并运行

点击《[在 Linux 下使用你的网站主机作为加密代理服务器][4]》一文中间的下载链接"[可以在此下载脚本][5]"

   [4]: http://sprayfly.com/2009/07/05/%e5%9c%a8-linux-%e4%b8%8b%e4%bd%bf%e7%94%a8%e4%bd%a0%e7%9a%84%e7%bd%91%e7%ab%99%e4%b8%bb%e6%9c%ba%e4%bd%9c%e4%b
8%ba%e5%8a%a0%e5%af%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8/ (Permanent Link to 在 Linux 下使用你的网站主机作为加密代理服务器)

   [5]: http://files.getdropbox.com/u/316115/tunnel.sh

用文本编辑器打开脚本文件,

修改"export SSH_HOST=[admin@yoursite.com][6] # username@host"一行,"admin"改成步骤1提到的用户名,"[yoursite.com][7]"改成主机的地址,域名或IP均可。

   [6]: mailto:admin@yoursite.com

   [7]: http://yoursite.com

修改"ssh -f -D 9999 $SSH_HOST "if [ -f ~/.tunnel ]; then……"一行的数字"9999"为希望设置成的本地端口号,一般习惯"7070"。

保存文件

进入控制台,输入


    su


    (输入root密码)


    cp /(下载目录)/tunnel.sh /bin


    cd /bin


    chmod u+x tunnel.sh

以上命令是把启动与关闭SSH tunnel的脚本放到/bin 目录中并设置好权限。

 4,配置firefox

启动Firefox,打开[https://addons.mozilla.org/en-US/firefox/addon/5189][8],点击安装"autoproxy"插件

   [8]: https://addons.mozilla.org/en-US/firefox/addon/5189

安装后重启firefox,选择订阅推荐的"gfwlist"

点击右上角出现的"福"字,

点击菜单项"代理服务器"->"编辑代理服务器"

添加一项代理,名字任意,代理主机"127.0.0.1",端口"7070"(端口号为步骤3中自行指定的,请根据步骤3的设置进行修改),选中"socks5",点击"确定"。

在Firefox主窗口点击菜单"编辑"->"首选项",进入窗口,点击"高级"->"网络"->"设置",选中"自动检测……",点击"确定",再"确定"。

(此处忽略介绍在Firefox中添加Flashplayer插件的方法)

打开"about:config"页面,搜索"network.proxy.socks_remote_dns",值改为"true",这是为了正确显示Youtube的视频。

至此Firefox配置完毕,可以根据"gfwlist"的记录自动识别需要代理的网站,可以测试一下:[搜狐][9],[Youtube][10],。

   [9]: http://www.sohu.com/

   [10]: http://www.youtube.com/

 5,管理SSH tunnel

启用SSH tunnel:

打开控制台,输入

/bin/tunnel.sh

会显示"创建 SSH 隧道",当返回命令输入状态的时候,SSH tunnel就建立好了,这时候就可以使用Firefox浏览了。

关闭SSH tunnel:

在控制台中再次输入

/bin/tunnel.sh

会显示"关闭 SSH 隧道",当返回命令输入状态的时候,SSH tunnel就关闭了。

敬请订阅我们:http://feeds2.feedburner.com/chinagfwblog,在twitter跟随我们:http://twitter.com/cdt。翻墙工具介绍和下载:http://www.sesawe.org/和http://www.sesawwe.net/。![][11]

   [11]: https://blogger.googleusercontent.com/tracker/5500297126185736776-4138888403896014611?l=www.chinagfw.org

Contentes HTML URL: http://www.chinagfw.org/2009/09/linuxssh-tunnel.html

Send By Feed RSS2eMail BOT V2.65
Admin By Liuxing99
Technical Details
Message-ID: <4ac255b7$3@news.liuxing99.3322.org>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!Xbb.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!61.160.212.82.MISMATCH!www.shinco.com!news.liuxing99.3322.org!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 85629cb6ee,de97cda4d007d756,start
X-Google-Attributes: gid85629cb6ee,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!Xbb.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!61.160.212.82.MISMATCH!www.shinco.com!news.liuxing99.3322.org!not-for-mail
From: RSS Feed For GFW Blog <gfwblog-list@szb66.vicp.net>
Newsgroups: cn.comp.hacker
Subject:  在Linux环境中建立SSH tunnel
Date: Tue, 29 Sep 2009 15:17:00 -0000
Organization: A poorly-installed InterNetNews site
Lines: 70
Message-ID: <4ac255b7$3@news.liuxing99.3322.org>
NNTP-Posting-Host: 58.209.241.164
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: base64
X-Trace: www.shinco.com 1254249942 32721 58.209.241.164 (29 Sep 2009 18:45:42 GMT)
X-Complaints-To: news@www.shinco.com
NNTP-Posting-Date: Tue, 29 Sep 2009 18:45:42 +0000 (UTC)
Received-Path: <gfwblog-list@szb66.vicp.net>
X-Feed-By: news.liuxing99.3322.org
User-Agent: Feed RSS2eMail BOT V2.65
X-Gateway-Administrator: bianlule@bianlule.3322.org
X-Gateway-From: dnews-gateway@news.liuxing99.3322.org