大网数据广告活动
服务器运维问答

SSH authentication sequence and key files : explain

· 52CE 我爱测

As a background to troubleshooting various problems using SSH and rsync with key pairs, I wanted a straightforward overview of the sequence of events that takes place during SSH authentication, and how each of the several client …

问题原文

原帖链接 · gwideman · CC BY-SA 4.0

As a background to troubleshooting various problems using SSH and rsync with key pairs, I wanted a straightforward overview of the sequence of events that takes place during SSH authentication, and how each of the several client and host files plays its part.

Google found many explanations at detailed level, with either a narrow scope, or whose broad scope was cluttered with those details. Not to mention many incorrect or confused explanations and forum posts.

I ended up creating a couple of diagrams to clarify two things:

  • What files and actions are involved in preparing for SSH communication using keys
  • What those files do during the process of establishing a connection.

I will post these in an answer below.

已采纳解答

原帖链接 · gwideman · CC BY-SA 4.0

The following answer explains the files needed to prepare for ssh authentication using public-private key pairs ("Public Key Infrastructure" or "PKI"), and how those files are used during an actual ssh session. Some specifics here use names and directories that apply to linux, but the principles apply across all platforms, which use programs and files parallel to these. The main features of interest are:

  • User machine
    • User key pair: Public and private, which the client-side user has to create using ssh-keygen, creating files with names such as:
      • ~/.ssh/id_rsa (private) and
      • ~/.ssh/id_rsa.pub (public)
      • In preparation, must be given to host's authorized_keys file
    • ~/.ssh/known_hosts
      • which receives the public key from the server, if user accepts it on first log in.
  • Host (server) machine
    • Host key pair: Public and Private
      • are automatically created at some point like installation of openssh on the server. Typical names:
      • /etc/ssh/ssh_host_rsa_key (private)
      • /etc/ssh/ssh_host_rsa_key.pub (public)
      • host offers the public key to the client-side user the first time the client-side user tries to connect with ssh. Client will store host's key in known_hosts
    • ~/.ssh/authorized_keys
      • In preparation, must be given the public key of each user who will log in.
  • Sequence of events in an actual SSH (or rsync) session, showing how the files are involved.

(Note that there are two different common signature algorithms, RSA and DSA, so where this discussion uses 'rsa', the string 'dsa' could appear instead.)

Configuration/preparation

SSH connection and use

I hope these diagrams will be helpful.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。