
如果有人之前問過這個問題,我深表歉意,但我目前正在嘗試找到解決方案,讓我們可以建立類似於 RDP 網關工作方式的 SSH 連線。對於那些不熟悉的人來說,RDP 網關本質上允許您透過另一台伺服器代理 RDP 連線。遠端桌面將透明地透過 RDP 網關伺服器進行身份驗證,並從那裡建立與端點伺服器的連接,允許您透過私人 IP 位址或內部 DNS 名稱引用端點伺服器,從而限制您的暴露。
目前我正在考慮的是透過 SSH 設定連接埠轉發,以便我們需要能夠存取隧道代理後面的每台伺服器都位於由中點伺服器轉發的不同連接埠上。然而,這感覺不是一個最佳解決方案,所以我有興趣知道是否有更好的方法來做到這一點。
答案1
在 SSH 術語中,您經常談論堡壘主機或者跳轉伺服器- 接受傳入 SSH 連線的單一電腦(通常位於 DMZ 中),然後您可以從該電腦與您管理的實際系統建立 SSH 連線。
==> | Server1 |
_________ ___________ / ---------
| user PC | ===(SSH on port 22)===> | jump host | ===(SSH on port 22)== ==+> | Server2 |
_________ ___________ \ _________
==> | Server3 |
通常,為了提高安全性,跳轉伺服器需要雙重認證和/或僅在建立 VPN 連線後接受傳入的 SSH 會話。
OpenSSH 允許您在單一命令中進行配置,而不是先登入跳轉主機並從命令提示字元啟動第二個 SSH 會話
我更喜歡在 my 中明確設置所有設置,~/.ssh/config
並為每個主機設置一個簡短的別名。這樣我就不需要使用任何命令列標誌,只需輸入 less 並使用即可ssh Destination
完成。
Host jumphost
Hostname jumphost.example.com
User serverfault
ForwardAgent yes
AddKeysToAgent yes
UseKeychain yes # Specific to OS X
IdentityFile ~/.ssh/id_rsa.jumphost
Host server1
Hostname server1.int.example.com
User hbruijn
ForwardAgent yes
AddKeysToAgent yes
UseKeychain yes # Specific to OS X
IdentityFile ~/.ssh/id_rsa.int.example.com
ProxyJump jumphost
ProxyJump
是一個相對較新的設置,我發現它比ProxyCommand
.現在ssh server1
將完全按照您的需求進行操作,首先建立一個會話[email protected]
作為第一跳,您可以選擇使用不同的 ssh 金鑰和不同的使用者名稱從該會話隧道到下一跳[email protected]
。
您也可以直接從命令列使用 ProxyJump 命令:
ssh -J [email protected] [email protected]
中討論了一種不同的方法本次問答
答案2
規範的解決方案是部署 IPv6(和/或 VPN)並從一開始就避免這種解決方法,但如果您現在無法做到這一點,那麼它被稱為跳線盒或堡壘主機或類似術語。它只是您放置的一台計算機,您的使用者可以使用 ssh 登錄,然後進一步 ssh 進入該機器具有網路存取權限的內部主機。該ssh
命令甚至有一個命令列選項,可以透過跳轉主機自動連線。
-J destination
Connect to the target host by first making a ssh connection to
the jump host described by destination and then establishing a
TCP forwarding to the ultimate destination from there. Multiple
jump hops may be specified separated by comma characters. This
is a shortcut to specify a ProxyJump configuration directive.
Note that configuration directives supplied on the command-line
generally apply to the destination host and not any specified
jump hosts. Use ~/.ssh/config to specify configuration for jump
hosts.