Ssh

ssh 埠轉發不起作用。得到錯誤

  • February 12, 2021

我有一臺本地筆記型電腦 MacOS,因此稱為localmachavingmacuser需要由遠端伺服器控制(通過觸發 ssh 命令),因此稱為remotelinuxhave linuxuser

localmac能夠成功ssh linuxuser@remotelinux

在我的localmac我確實使用以下命令發布隧道:

ssh -fnN -R 4444:localhost:22  linuxuser@remotelinux

現在,我remotelinux嘗試使用以下方法複製密鑰,但出現錯誤:

$ ssh-copy-id -p 4444 macuser@localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/linuxuser/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: ERROR: ssh_exchange_identification: Connection closed by remote host

我了解上述失敗,但是我嘗試在 remotelinux 上觸發主機名命令,如下所示:

[linuxuser@remotelinux ~]$ ssh -p 3334 macuser@localhost 'hostname' -vvvv
ssh_exchange_identification: Connection closed by remote host
[linuxuser@remotelinux ~]$ ssh -p 3334 macuser@localhost -vvvv
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolving "localhost" port 3334
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to localhost [::1] port 3334.
debug1: Connection established.
debug1: identity file /home/linuxuser/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/linuxuser/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
ssh_exchange_identification: Connection closed by remote host

localmac我發現以下消息為我觸發的每個 ssh 命令列印remotelinux

SSH tunneling: connect_to localhost port 22: failed

你能建議我如何讓它工作嗎?

MacOS 筆記型電腦預設禁用遠端登錄,因此 SSH 失敗。轉到首選項並啟用它。

引用自:https://unix.stackexchange.com/questions/634089