美文网首页
SSH 代理连接

SSH 代理连接

作者: 华阳_3bcf | 来源:发表于2018-07-10 14:31 被阅读0次

OpenSSH connection via proxy

Command line for proxy

用很长的命令行来实现,逻辑也在命令行中表达的很清晰。
具体是:

ssh internal_vm -o ProxyCommand="xxxx"

例如:

$ ssh -i group_vars/iot_rsa redhat@10.0.1.4 -o ProxyCommand="ssh -q -W %h:%p -i group_vars/iot_rsa redhat@40.83.75.19"
Last login: Tue Aug  7 07:24:01 2018 from 10.0.0.4
[redhat@roy-hk-de-vm-hdp-2 ~]$

参数解释,具体可以 man ssh_config / ssh
-i 出现两次,分别指定目标机和proxy 连接时用到的private key
-o 指定 option,这个例子告诉它使用ProxyCommand
-q quite mode, 静音模式
-W host:port 转发 Requests that standard input and output on the client be for-warded to host on port over the secure channel.
%h:%p Token remote host : remote port

另一种使用nc命令(netcat)实现

这能解决 https 代理的问题,有些机器默认没有安装nc,需要单独安装。

假设本地SSH代理的监听端口是3000,则ProxyCommand为

ProxyCommand nc -x 127.0.0.1:3000 %h %p

其中%h表示目标地址,%p是目标端口。这句可以用在命令行里,例如

ssh -o ProxyCommand="nc -x 127.0.0.1:3000 %h %p" git@github.com

nc也可以用于HTTPS代理,这需要指定所使用的协议,即添加 -X connect 参数。比如ssh_config中的例子

ProxyCommand nc -X connect -x 192.168.1.1:8080 %h %p

System-wide OpenSSH config file

/etc/ssh/ssh_config :

This files set the default configuration for all users of OpenSSH clients on that desktop/laptop and it must be readable by all users on the system.

User-specific OpenSSH config file

这是常用方式,配置好文件,用很短命令行就可以登录。而且修改配置文件只要理解就行了,不需要大量的记忆。

~/.ssh/config or $HOME/.ssh/config :

This is user’s own configuration file which, overrides the settings in the global client configuration file, /etc/ssh/ssh_config.

$ cat ~/.ssh/config
Host hdp1
    User redhat
    IdentityFile /home/centos/tmp/706/group_vars/iot_rsa
    ProxyCommand ssh -q -W %h:%p redhat@40.83.73.163
    HostName roy-hk-deploy-vm-hdp-01

Another example:

Host roy1
    User redhat
    ProxyCommand ssh -i /Users/royzeng/repo/723/group_vars/iot_rsa -q -W %h:%p redhat@40.83.75.19
    HostName roy-hk-de-vm-hdp-1
    IdentityFile /Users/royzeng/repo/723/group_vars/iot_rsa

Host *
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null

参数解释:
Host roy1 ssh连接时使用的主机名简称
ProxyCommand 定义怎么连接proxy
IdentityFile 连接目标机的 private key
User 连接目标机的 用户名
StrictHostKeyChecking no 不检查HostKey 可以直接连接(不确认)

And then you can directly connect the server behind proxy now.

e.g.

$ ssh hdp1

$scp aaa.txt hdp1:/tmp/bbb.txt

相关文章

  • SSH 代理连接

    OpenSSH connection via proxy Command line for proxy 用很长的命...

  • 利用反向代理实现内网的ssh连接

    内容实现了再补 参考文章:SSH如何反向代理稳定穿透内网利用ssh反向代理以及autossh实现从外网连接内网服务器

  • GIT相关

    一些用法 ssh配置代理 如果电脑联网需要走代理,然后发现git使用ssh协议无法连接到github,这里以win...

  • autossh实现内网穿透

    autossh作用实现内网穿透,之前用过ssh反向代理,但是ssh反向代理在网络不稳定的环境下面就会很麻烦,连接断...

  • 通过代理连接ssh

    主要参考该篇文章,为了防止文章丢失,转载至此。 注意在进行./configure时在MAC下可能会错误,这个在别的...

  • 监听端口被占用处理方式

    故事开始:我在校外连接学校服务器先用 Bitvise SSH Client 连接代理,再用 MobaXterm 连...

  • kolla nova_ssh docker的作用

    nova-ssh 中开启了一个sshd服务,用于作为nova ssh uuid 连接登录虚拟机的一个ssh代理,可...

  • ssh ProxyJump 通过代理机跳转内网

    ssh 通过代理机跳转内网 ssh 命令有一种简单的方法来利用跳板主机通过单个命令连接到远程主机。 ssh 可以使...

  • kex_exchange_identification: Con

    出现这个原因有多种可能,我出现这个原因是因为使用了机场的代理服务,代理服务节点禁止了github的ssh连接。解决...

  • Linux知识积累

    SSH连接 ssh通过跳板机连接内网服务器,发现能ping通连接不上,检查了/etc /ssh/ssh_confi...

网友评论

      本文标题:SSH 代理连接

      本文链接:https://www.haomeiwen.com/subject/gkwfpftx.html