ssh远程连接config配置及原理

转自:https://deepzz.com/post/how-to-setup-ssh-config.html

1.配置例子

Host 编译机
    HostName xx.xx.xx.xx
    User name
    Port xxx
    IdentityFile /home/yonghu/.ssh/id_rsa
    PasswordAuthentication no
    ProxyCommand ssh -W %h:%p 跳板机

Host 跳板机
    HostName xx.xx.xx.xx
    User name
    Port xxx
    IdentityFile /Users/yonghu/.ssh/id_rsa
    PasswordAuthentication yes

配置参数:

  • Host:用于执行 SSH 命令的时候如何匹配到该配置。 
  • IdentityFile:认证文件,指定读取的认证文件路径。是本端的私钥文件,即你要登录的服务器的前一跳。
  • PasswordAuthentication:是否使用密码进行身份验证,yes(default)/no。如果你对服务器安全要求很高,那么禁用密码登录是必须的。因为使用密码登录服务器容易受到暴力破解的攻击,有一定的安全隐患。
  • ProxyCommand:指定连接的服务器需要执行的命令。%h,%p,%r。

上述的ssh -W 作用如下://不太明白。

-W host:port
Requests that standard input and output on the client be forwarded to host on port over the secure channel. 请求将客户机上的标准输入和输出通过安全通道转发到端口上的主机。

 2.ssh原理

https://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html

公钥远程登录原理:

  1. 用户将自己的公钥储存在远程主机上;
  2. 申请远程登录时,远程主机会向用户发送一段随机字符串,用户用自己的私钥加密后,再发回来。
  3. 远程主机用事先储存的公钥进行解密,如果成功,就证明用户是可信的,直接允许登录shell,不再要求密码。

非对称加密。

//https://www.jianshu.com/p/33461b619d53,这个链接中讲公钥登录和上述原理不一样。。。是server发字符串时已经用client的公钥加密了。。。但暂时认为上述简单的流程比较好理解。

 

posted @ 2022-07-28 22:24  lypbendlf  阅读(946)  评论(0编辑  收藏  举报