透過堡壘主機的 SSH 隧道

透過堡壘主機的 SSH 隧道

我在透過堡壘主機建立 ssh 隧道時遇到問題。

瀏覽了各種可能解決該問題的 SE 問題後,沒有任何解決方案。

我的 ssh 設定檔(本地)

Host www
    HostName ***
    IdentityFile ~/.ssh/key.pem
    ProxyCommand ssh root@bastion -W %h:%p

Host bastion
    HostName ***
    IdentityFile ~/.ssh/key.pem
    StrictHostKeyChecking      no
    ProxyCommand               none
    ForwardAgent               yes

我在堡壘伺服器上新增了必要的設定選項(/etc/ssh/sshd_config):

PermitTunnel yes
AllowTCPForwarding yes
PermitOpen any
TCPKeepAlive yes

但我收到以下錯誤:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: /etc/ssh/ssh_config line 59: Applying options for www
debug1: Executing proxy command: exec ssh root@bastion -W ****:22
debug1: permanently_set_uid: 0/0
debug1: permanently_drop_suid: 0
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file ~/.ssh/key.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
channel 0: open failed: administratively prohibited: open failed
stdio forwarding failed
ssh_exchange_identification: Connection closed by remote host

此設定有一個警告,目標主機 (www) 位於 AWS VPC 中,並且只能從堡壘進行尋址。我的假設是,這不應該成為問題,因為路由是從堡壘完成的,但這是我最後的想法,因為這是這種情況下的問題。

答案1

這相當煩人。事實證明,AWS AMI 在其authorized_keys 中停用了連接埠轉送!當 sshd 配置中的所有內容看起來都正確時,調試起來會很棘手。

〜/.ssh/authorized_keys

no-port-forwarding,no-agent-forwarding,no-X11-forwarding

相關內容