> For the complete documentation index, see [llms.txt](https://wiki.halfcoffee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.halfcoffee.com/microsoft/windows-ssh-an-zhuang-ji-mian-mi-deng-lu.md).

# Windows SSH 安装及免密登录

### 目录

1. [Windows SSH 安装及免密登录](broken://pages/jgscjxEGPhaf8J9ENIxV)
   1. [安装 openssh](broken://pages/jgscjxEGPhaf8J9ENIxV)
   2. [免密登陆设置](broken://pages/jgscjxEGPhaf8J9ENIxV)
   3. [排错](broken://pages/jgscjxEGPhaf8J9ENIxV)

### 安装 openssh

下载链接：

<https://github.com/PowerShell/Win32-OpenSSH/releases>

我使用的是 [openssh-win64-v9.4.0.0.msi](https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.4.0.0p1-Beta/OpenSSH-Win64-v9.4.0.0.msi)

安装完毕后，系统会自动配置好下列 service 并自动启动：

![image-20231107183514826](https://942287112-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfiaHejDGLOo45USRaqSm%2Fuploads%2FKMEbNA15NRGKf5LtGwXA%2Fimage%2020231107183514826.png?alt=media)

通过 SSH client 登陆正常。

### 免密登陆设置

在用户目录（此处是 user\administrator）下创建 `.ssh\authorized_keys` 文件，填入 client 的 `id_rsa.pub`，需要注意不能换行。

![image-20231107184132635](https://942287112-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfiaHejDGLOo45USRaqSm%2Fuploads%2FijF9JXZJmoZUltaeldZA%2Fimage%2020231107184132635.png?alt=media)

之后修改 \` C:\ProgramData\ssh\sshd\_config\` 文件：

```
# 启用公钥登陆
PubkeyAuthentication yes

# administrator 用户同样使用 authorized_keys 进行免密登陆（默认是 __PROGRAMDATA__/ssh/administrators_authorized_keys）
Match Group administrators
       AuthorizedKeysFile ~/.ssh/authorized_keys
```

测试：

```
[root@Docker-host]# ssh 
Microsoft Windows [版本 6.3.9600]
(c) 2013 Microsoft Corporation。保留所有权利。

administrator@DNS C:\Users\Administrator>exit
Connection to 10.10.50.6 closed.
```

### 排错

如果修改了配置后不知道是否生效，或者登陆有问题，可以使用下列方式进行测试：

```
# 停掉 sshd
net stop sshd 

# 手动启用 sshd，指定修改后的配置文件，开启 debug 记录
sshd.exe -f C:\ProgramData\ssh\sshd_config -d 
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wiki.halfcoffee.com/microsoft/windows-ssh-an-zhuang-ji-mian-mi-deng-lu.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
