我安装了 Ubuntu 22.04 并使用激活了 ssh 服务
sudo apt install ssh
Run Code Online (Sandbox Code Playgroud)
我尝试通过 putty 使用 ssh 从 Windows 连接到我的 Ubuntu,结果成功了。putty 要求信任 Ubuntu 的密钥,一切都很好。
但是,如果我转到 Ubuntu 并尝试查看安装 ssh 服务时生成的公钥和私钥,它们并不在目录中~/.ssh/。
有人可以解释一下吗?
使用 SSH 连接与生成 SSH 公钥和私钥之间存在差异。请注意,您问题中的术语(公钥和私钥、“id 文件” ~/.ssh/)会导致您考虑用户生成的 SSH 密钥对。
您所指的目录 ( ~/.ssh/) 用于存放用户生成的 SSH 密钥对、known_hosts文件等,安装 SSH 本身不会生成用户密钥对。如果您想从 Windows 中使用 SSH 密钥对进行连接,您需要执行以下操作:
这是关于超级用户的问答,详细介绍了如何在 Windows 上设置 SSH 密钥以与 PuTTY 一起使用,另一则关于密钥存储原因和方式的问答。
但是,如果您指的是安装 SSH 时生成的 SSH 主机密钥,这些密钥位于 内部/etc/ssh,并且可以使用以下命令列出:
$ ls -la /etc/ssh/ssh_host*
-rw------- 1 root root 1373 May 8 2020 /etc/ssh/ssh_host_dsa_key
-rw-r--r-- 1 root root 597 May 8 2020 /etc/ssh/ssh_host_dsa_key.pub
-rw------- 1 root root 492 May 8 2020 /etc/ssh/ssh_host_ecdsa_key
-rw-r--r-- 1 root root 169 May 8 2020 /etc/ssh/ssh_host_ecdsa_key.pub
-rw------- 1 root root 399 May 8 2020 /etc/ssh/ssh_host_ed25519_key
-rw-r--r-- 1 root root 89 May 8 2020 /etc/ssh/ssh_host_ed25519_key.pub
-rw------- 1 root root 2590 May 8 2020 /etc/ssh/ssh_host_rsa_key
-rw-r--r-- 1 root root 561 May 8 2020 /etc/ssh/ssh_host_rsa_key.pub
Run Code Online (Sandbox Code Playgroud)
公共主机密钥保存在客户端计算机上(如known_hosts),以验证远程计算机的身份并将连接标记为“可信”。在 Ubuntu 上,已知主机保存在(在 Windows 中~/.ssh/known_hosts请参阅超级用户)。