【问题标题】:Advance ssh config file高级 ssh 配置文件
【发布时间】:2017-09-20 17:07:02
【问题描述】:

如何直接ssh到远程服务器,下面是详细描述。

Local machine ---> Jump1 ----> Jump2 ----> Remote Server

从本地机器无法直接访问远程服务器并且 Jump2 被禁用 远程服务器只能从 Jump2 访问

远程服务器没有 sshkegen,我们必须手动输入密码。

Local Machine我们使用ip和端口2222访问Jump1然后从Jump 1我们使用主机名默认端口22访问Jump2

通过 ssh/config 文件,我们可以毫无问题地访问 jump2 服务器。但我的要求是直接访问远程服务器。

有什么方法可以让我不介意输入远程服务器的密码。

日志

 ssh -vvv root@ip address
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /root/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ip address [ip address] port 22.

我的配置文件

Host jump1
    Hostname ip.109
    Port 2222
    User avdy

Host jump2
    Hostname ip.138
    Port 22
    ProxyCommand ssh -W %h:%p jump1
    User avdy

Host remote-server
    Hostname ip.8
    Port 22
    ProxyCommand ssh -W %h:%p jump2
    User root

【问题讨论】:

  • 你不需要远程服务器上的 ssh-keygen 来设置无密码身份验证,除非它在 ​​sshd-config 中被禁用。

标签: ssh ssh-tunnel ssh-config


【解决方案1】:

设置你的~/.ssh/config:

Host Jump1
  User jump1user
  Port 2222
Host Jump2
  ProxyCommand ssh -W %h:%p Jump1
  User jump2user
Host RemoveServer
  ProxyCommand ssh -W %h:%p Jump2
  User remoteUser

或者使用新的 OpenSSH 7.3:

Host RemoveServer
  ProxyJump jump1user@Jump1,jump2user@Jump2
  User remoteUser

然后你可以简单地使用ssh RemoteServer进行连接

【讨论】:

  • 我的版本 openssh-server-5.3p1 但上面的配置文件示例无法正常工作。收到错误ssh: connect to host ip.address port 22: Connection timed out
  • 跳转主机只有一个用户,远程服务器有不同的用户。
  • 设置LogLevel DEBUG3并发布日志。哪个连接超时?
  • Jump1 添加Port 选项。
  • 不要使用ssh -vvv root@ip address 连接。使用配置文件中定义的名称:ssh ff1bp-vsns0001n
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
  • 1970-01-01
  • 2014-04-12
  • 1970-01-01
  • 2013-06-24
  • 2018-09-06
相关资源
最近更新 更多