歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在Debian 7/Ubuntu 13.10 上使用隧道封裝SSH連接

在Debian 7/Ubuntu 13.10 上使用隧道封裝SSH連接

日期:2017/2/28 14:36:54   编辑:Linux教程

隧道 被設計用於遠端客戶端和本地(可通過inetd啟動)或遠端服務器間的SSL加密封裝。它可以用於為inetd進程增加SSL功能,像POP2(譯注:厄,POP2這個服務還有人用麼?),POP3和IMAP服務而不必改變程序代碼。隧道使用OpenSSL庫用於加密,因此它支持任何被編譯進庫的加密算法。簡而言之,隧道可以使任何一個不安全的端口變得安全加密。

在本篇中,我會描述如何通過SSL水稻封裝SSH。這個步驟非常簡單。你需要在你的客戶端PC和遠程PC都已經安裝運行了sshd。

我正在使用下面提到的兩個系統。

遠程系統:

操作系統: Debian 7
IP 地址: 192.168.1.200/24

客戶端(本地) 系統:

操作系統: Ubuntu 13.04 desktop
IP 地址: 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 incorporated
into 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 blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:IN
State or Province Name (full name) [Some-State]:Tamilnadu
Locality Name (eg, city) []:Erode
Organization Name (eg, company) [Internet Widgits Pty Ltd]:unixmen
Organizational Unit Name (eg, section) []:Technical
Common Name (e.g. server FQDN or YOUR name) []:server.unixmen.com
Email Address []:[email protected]

# 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.pid
cert = /etc/stunnel/stunnel.pem
[ssh]
accept = 192.168.1.200:443
connect = 127.0.0.1:22

上面的幾行說明了stunnel在哪裡尋找證書文件和哪裡接收和轉發ssh鏈接。在本例中,stunnel會接收來自443端口的流量並會轉發給22端口。

保存並關閉文件。

現在讓我們啟用stunnel服務。要這麼做,編輯文件 /etc/default/stunnel4:

# vi /etc/default/stunnel4

改變行從 ENABLED = 01

# /etc/default/stunnel
# Julien LEMOINE <[email protected]>
# September 2003

# Change to one to enable stunnel automatic startup
ENABLED=1
FILES="/etc/stunnel/*.conf"
OPTIONS=""

# Change to one to enable ppp restart scripts
PPP_RESTART=0

接著使用命令啟用stunnel服務:

# service stunnel4 start

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved