# SSH 密钥

Source: https://bflops.com/docs/ssh-keys

在 macOS、Linux 或 Windows 上创建 SSH 密钥，并把它的公钥粘贴到 bFLOPS。



SSH 密钥是一对文件：留在你电脑上的私钥，和你交给 bFLOPS 的公钥。机器只允许持有私钥的电脑登录。

## 检查你是否已有密钥 [#check-for-a-key-you-already-have]

```bash title="macOS、Linux、Windows PowerShell"
ls ~/.ssh/*.pub
```

如果列出了 `id_ed25519.pub` 这样的文件，直接跳到[复制公钥](#copy-the-public-key)。

## 创建密钥 [#make-a-key]

在 macOS 或 Linux 的终端中，或在 Windows 10 和 11 的 PowerShell 中运行：

```bash title="在你的电脑上"
ssh-keygen -t ed25519
```

按回车，保留建议的文件位置。密码短语可以不设：如果有人复制了你的文件，它可以保护密钥。

## 复制公钥 [#copy-the-public-key]

打印它：

```bash title="在你的电脑上"
cat ~/.ssh/id_ed25519.pub
```

复制整行，从 `ssh-ed25519` 到行尾。启动机器时，把它粘贴到 **SSH 公钥**。

<Callout kind="warning">
  不要粘贴或分享不带 

  `.pub`

   的文件。那是你的私钥。
</Callout>

## bFLOPS 接受的密钥 [#keys-bflops-takes]

* 类型：`ssh-ed25519`、`ssh-rsa`、`ecdsa-sha2-nistp256`、`ecdsa-sha2-nistp384`、`ecdsa-sha2-nistp521`，以及硬件密钥（`sk-ssh-ed25519@openssh.com`、`sk-ecdsa-sha2-nistp256@openssh.com`）。
* 每台机器一个密钥，写在一行中，最多 4,096 个字符。

## 使用其他密钥文件 [#use-another-key-file]

如果你的密钥不是默认的那个，用 `-i` 告诉 SSH 使用它：

```bash title="在你的电脑上"
ssh -i ~/.ssh/my_key -p 40022 root@203.0.113.7
```

## 下一步 [#next]

[连接你的机器](/docs/connect)
