推进ssh配置文件

时间:2017-04-24 06:14:09

标签: ssh ssh-tunnel ssh-config

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

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

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

访问远程服务器

远程服务器没有sshkegen我们必须手动提供密码。

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

使用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

1 个答案:

答案 0 :(得分: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

进行连接即可