当连接到unix盒子时,它如何知道你在桌面上安装了SSH?

当你使用像腻子连接到一个Linux的东西,你设置你的SSH密钥等

连接时,它如何告诉服务器你想使用你的SSH密钥连接?

SSH是作为一个服务在一个特定的端口上运行,还是只是通过你的私钥,然后login服务看到并试图连接使用它?

只是寻找一个相当高层次的理解(也许一些细节,如果你想…)

服务器端configuration为允许的authenticationtypes。 然后客户做出相应的反应。 从我的Linux机器上,我运行一个ssh会话到一个带有debugging输出的主机,以显示它的function:

OpenSSH_5.3p1, OpenSSL 1.0.0-fips-beta4 10 Nov 2009 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Connecting to blahblahblah [ip_address] port 22. debug1: Connection established. debug1: identity file /home/username/.ssh/identity type -1 debug1: identity file /home/username/.ssh/id_rsa type 1 debug1: identity file /home/username/.ssh/id_dsa type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_4.7 debug1: match: OpenSSH_4.7 pat OpenSSH_4* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.3 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host 'hostname' is known and matches the RSA host key. debug1: Found key in /home/username/.ssh/known_hosts:13 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-with-mic,password debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_500' not found debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_500' not found debug1: Unspecified GSS failure. Minor code may provide more information debug1: Next authentication method: publickey debug1: Offering public key: /home/username/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 277 debug1: Authentication succeeded (publickey). debug1: channel 0: new [client-session] debug1: Entering interactive session. debug1: Sending environment. debug1: Sending env XMODIFIERS = @im=none debug1: Sending env LANG = en_US.UTF-8 

所以你可以看到它协商了一个协议,然后开始提供authenticationtypes。 当命中公钥authentication时,发现一个密钥,发送一个密钥,然后服务器接受该密钥,然后authentication成功,并且不再进行任何authentication机制。 如果它没有处理密钥,我会得到密码提示,因为这将是唯一的方法来尝试。

互联网协议的优点是大多数都有详细的工程文档。 在这种情况下, RFC 4251引用了许多其他SSH相关的RFC。 你所追求的是RFC 4252 , 安全shell(SSH)authentication协议 。 从框架部分:

服务器通过告诉客户端在任何给定的时间可以使用哪种authentication方法来继续交换来驱动authentication。 客户可以按任意顺序自由地尝试服务器列出的方法。 这使得服务器可以根据需要完全控制authentication过程,而且当服务器提供多种方法时,也为客户端提供了足够的灵活性,使客户端可以使用其支持的方法或对用户最方便的方法。

在这一点上,你的客户端(PuTTY)将检查它是否有任何使用键(通过选美)。 如果它find适用于该主机的私钥,则使用该私钥。 如果它发现一个encryption的私人密钥,Pageant会要求input密码并caching。 然后putty告诉服务器“publickey”,并且过程按照RFC 4252第7部分进行。如果configuration这样做(通常通过PAM),SSH服务器可以回退到密码authentication。

使用腻子,您需要在configuration中指定密钥或运行腻子代理(pageant.exe)并加载密钥。 服务器真的不知道你的客户端没有告诉它什么,客户端的通信在很大程度上取决于你的configuration。

腻子文件:

  • 第4.20章: Auth面板
  • 第9章: 使用Pageant进行身份validation

它不会发送你的私钥,这是私人/公共密钥对的美丽。

总之,有一对密钥,一个私密密钥,绝不会传给任何人, 和公共密钥,你可以发送到风,或张贴到网上,无论如何。

有趣的是,即使你知道一个公钥,要算出相应的私钥也是天文数字。 同时,用一个密钥encryption的任何消息只能与另一个密钥解密。

ssh使用的握手大概是这样的:

  • sshd服务器正在侦听TCP端口,通常是端口22。
  • ssh客户端连接到sshd服务器。
  • 有几个authentication选项,客户端尝试它们,直到服务器同意为止。 其中一个涉及“提供”公钥,将其发送到连接上。
  • 服务器将提供的公钥与它所知道的一个公钥进行比较。 如果已注册,则服务器接受密钥,然后开始validation密钥。 记住公钥是公开的,任何人都可以拥有它,提供它并不能保证你是你说的那个人。
  • 客户端获得私钥(其他人不应该拥有)并使用它来encryption一个值。 这是一个不同的值,我认为它是由服务器生成和发送的。
  • 客户端将encryption的值发送给服务器,服务器使用公钥对其进行解密。 如果该值与原始值相符,则certificate客户端具有与提供的公钥配对的私钥。

我现在不在PuTTY附近,但是在Auth或Login下,您可以select为每个保存的会话使用哪些密钥。 没有服务正在运行。

基本上,SSH握手将客户端和服务器支持的身份validation,数据encryption等方法进行比较,直到find可以同意或放弃的方法。 标准端口是tcp / 22,但有些人改变它以减less恶意攻击的企图。

我最喜爱的密钥对如何工作的解释器是Simon Tatham: 公钥authentication – 一个介绍