隧道 被设计用于远端客户端和本地(可通过inetd启动)或远端服务器间的SSL加密封装。它可以用于为inetd进程增加SSL功能,像POP2(译注:厄,POP2这个服务还有人用么?),,POP3和IMAP服务而不必改变程序代码。隧道使用OpenSSL库用于加密,因此它支持任何被编译进库的加密算法。简而言之,隧道可以使任何一个不安全的端口变得安全加密。
在本篇中,我会描述如何通过SSL水稻封装SSH。这个步骤非常简单。你需要在你的客户端PC和远程PC都已经安装运行了sshd。
我正在使用下面提到的两个系统。
远程系统:
操作系统: Debian 7IP 地址: 192.168.1.200/24
客户端(本地) 系统:
操作系统: Ubuntu 13.04 desktopIP 地址: 192.168.1.100/24配置远程系统
让我们在远程Debian 7服务器上安装stunnel包。
# apt-get install stunnel4
现在让我们像下面那样创建一个SSL证书。
# openssl genrsa 1024 > stunnel.key
示例输出:
Generating RSA private key, 1024 bit long modulus……………………………………..++++++……………….++++++e is 65537 (0x10001)# openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt
你会被询问若干个问题如国家、州、公司细节等。
You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter ‘.’, the field will be left blank.—–Country Name (2 letter code) [AU]:INState or Province Name (full name) [Some-State]:TamilnaduLocality Name (eg, city) []:ErodeOrganization Name (eg, company) [Internet Widgits Pty Ltd]:unixmenOrganizational Unit Name (eg, section) []:TechnicalCommon Name (e.g. server FQDN or YOUR name) []:server.unixmen.comEmail Address []:sk@unixmen.com# cat stunnel.crt stunnel.key > stunnel.pem# mv stunnel.pem /etc/stunnel/
现在我们需要配置stunnel来将 443(https)隧道到22(ssh)。这可以通过在/etc/stunnel/目录下创建stunnel.conf文件来实现:
# vi /etc/stunnel/stunnel.conf
并加入下面的行:
pid = /var/run/stunnel.pidcert = /etc/stunnel/stunnel.pem[ssh]accept = 192.168.1.200:443connect = 127.0.0.1:22
上面的几行说明了stunnel在哪里寻找证书文件和哪里接收和转发ssh链接。在本例中,stunnel会接收来自443端口的流量并会转发给22端口。
保存并关闭文件。
现在让我们启用stunnel服务。要这么做,编辑文件 /etc/default/stunnel4:
# vi /etc/default/stunnel4
改变行从 ENABLED = 0 到 1。
# /etc/default/stunnel# Julien LEMOINE <speedblue@debian.org># September 2003# Change to one to enable stunnel automatic startupENABLED=1FILES=”/etc/stunnel/*.conf”OPTIONS=””# Change to one to enable ppp restart scriptsPPP_RESTART=0
接着使用命令启用stunnel服务:
# service stunnel4 start
相关阅读:
Ubuntu 下配置 SSH服务全过程及问题解决
Ubuntu 12.04下安装Git,SSH及出现的Permission denied解决办法
Ubuntu 12.10下OpenSSH的离线安装方法
Ubuntu下SSH安装或设置
感受不同地域不一样的节奏与表象。