我有一台本地笔记本电脑MacOS,因此称为localmac
having macuser
,需要由远程服务器控制(通过触发ssh命令),因此称为remotelinux
having 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
你能建议我如何让它发挥作用吗?
答案1
MacOS 笔记本电脑上默认禁用远程登录,因此 SSH 失败。转到首选项并启用它。