V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
boogiefer
V2EX  ›  Linux

私钥登录跳板机,跳板机如何用密码验证的方式登录目标机器?

  •  
  •   boogiefer · 2016-10-12 18:47:32 +08:00 · 5580 次点击
    这是一个创建于 2724 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想要实现的:

    客户端(私钥) -> 跳板机(公钥) -> 目标机器 1 、目标机器 2 (密码验证)
    

    客户端用私钥登录跳板机,想用密码验证的方式登录不通的内网机器

    现在的配置:

    1. 跳板机有外网 IP , ssh_config 文件禁用了密码验证 PasswordAuthentication no,存放了公钥;
    2. 内网机器都是密码验证登录,没有启用密钥验证方式的登录;

    碰到的问题:

    跳板机会默认使用密钥验证的方式去登录内网机器,并且不会尝试密码验证的方式登录。

    10 条回复    2016-10-14 02:02:40 +08:00
    paulw54jrn
        1
    paulw54jrn  
       2016-10-12 18:50:16 +08:00
    ssh -A

    https://www.freebsd.org/cgi/man.cgi?query=ssh&sektion=1

    ```
    -A Enables forwarding of the authentication agent connection. This
    can also be specified on a per-host basis in a configuration
    file.

    Agent forwarding should be enabled with caution. Users with the
    ability to bypass file permissions on the remote host (for the
    agent's UNIX-domain socket) can access the local agent through
    the forwarded connection. An attacker cannot obtain key material
    from the agent, however they can perform operations on the keys
    that enable them to authenticate using the identities loaded into
    the agent.
    ```
    paulw54jrn
        2
    paulw54jrn  
       2016-10-12 18:50:57 +08:00
    我看错了.. 请忽略我
    boogiefer
        3
    boogiefer  
    OP
       2016-10-12 18:58:56 +08:00
    @paulw54jrn `- A` 命令是用来转发密钥的,内网机器并不支持密钥验证的方式登录
    xqin
        4
    xqin  
       2016-10-12 19:06:40 +08:00
    1. ssh 至跳板机, 并增加 -L 参数, 比如 -L 1234:目标机器 IP:端口
    2. 在完成上面这一步的时候,在 `客户端` 连接 127.0.0.1:1234 使用密码来登陆 目标机器.

    简单点讲就是 由`跳板机`做一下端口转发, 把 `目标机器`的`ssh 端口`转发过来, 然后在`客户端`上登陆`目标机器`.
    boogiefer
        5
    boogiefer  
    OP
       2016-10-12 19:11:58 +08:00
    @xqin 感谢答复,你的方法还没验证;

    我发现在跳板机 ~/.ssh/config 配置里面,添加内网 Host 并且把 `PasswordAuthentication` 设置成 `yes` 就可以了
    xqin
        6
    xqin  
       2016-10-12 19:13:08 +08:00
    再或者 使用 -F 参数, 重新指定 ssh_config 文件, 不让它使用系统默认的(在跳板机上登陆目标机器的时候).
    xqin
        7
    xqin  
       2016-10-12 19:15:28 +08:00   ❤️ 1
    `man ssh_config` 即可得到如下帮助信息:

    SSH_CONFIG(5) BSD File Formats Manual SSH_CONFIG(5)

    NAME
    ssh_config — OpenSSH SSH client configuration files

    SYNOPSIS
    ~/.ssh/config
    /etc/ssh/ssh_config

    DESCRIPTION
    ssh(1) obtains configuration data from the following sources in the fol ‐
    lowing order:

    1. command-line options
    2. user's configuration file (~/.ssh/config)
    3. system-wide configuration file (/etc/ssh/ssh_config)
    raysonx
        8
    raysonx  
       2016-10-12 21:14:16 +08:00 via iPad   ❤️ 1
    不明白为何要在跳板机 ssh_config 里禁止 ssh 客户端,注意客户端,禁止密码认证。
    应该是在 sshd_config 里禁止,而不是 ssh_config 。前者管别人登他,后者管他登别人。
    ywgx
        9
    ywgx  
       2016-10-12 21:44:14 +08:00 via iPhone
    去看看 xabcloud.com 的设计
    likuku
        10
    likuku  
       2016-10-14 02:02:40 +08:00
    跳板鸡上的 ~/.ssh/config 里 添加:
    ForwardAgent no

    即可
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1460 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:50 · PVG 07:50 · LAX 16:50 · JFK 19:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.