我刚刚开始工作,对使用 ssh 不太熟悉,我正在尝试创建一个从服务器到我家里的机器的反向 ssh 隧道。
我首先输入
ssh -v -f -R port-number1:localhost:port-number2 username@server-name
这有效。但是,当我输入 ssh -v -p port-number1 localhost 时,它会出现此错误。
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, 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: Connecting to localhost [127.0.0.1] port 52673.
debug1: Connection established.
debug1: SELinux support disabled
Could not create directory '/home/dev/.ssh'.
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/dev/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
ssh_exchange_identification: Connection closed by remote host
现在不知何故,我在服务器上的用户名是“dev”,它是根目录中的一个文件夹,在主目录中,有一个名为 ubuntu 的文件夹。当我尝试在服务器中查找 .ssh 时,它显示 home/ubuntu/.ssh 这可能是问题所在,但我不知道下一步该怎么做,因为我无权在服务器中移动目录。
最佳答案
在远程主机上运行此命令:
ssh -N user@remotehost -R port:localhost:port
其中 user 是远程主机上的用户,remotehost 是您想要反向 ssh 进入的盒子的 IP/域,port 是使用的端口(通常为 22,但如果不是保留端口,则可以是任意端口),而 localhost 就是字面上的 localhost。
然后尝试通过 ssh 进入远程主机。
关于linux - 执行反向 ssh 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45180676/