无法为 github 和 aws 生成 ssh 密钥(非法选项 -- C)

Posted

技术标签:

【中文标题】无法为 github 和 aws 生成 ssh 密钥(非法选项 -- C)【英文标题】:Unable to generate ssh keys for github and aws (illegal option -- C) 【发布时间】:2016-01-01 18:32:32 【问题描述】:

我一直在尝试使用我的 github 帐户设置 ssh,并按照https://help.github.com/articles/generating-ssh-keys/ 上的指南并运行那里列出的命令:我收到以下错误

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
illegal option -- C
Usage: ssh-keygen [options] [key1 key2 ...]

Where `options` are:
 -b nnn         Specify key strength in bits (e.g. 1024)
 -t dsa | rsa   Choose the key type.
 -c comment     Provide the comment.
 -e file        Edit the comment/passphrase of the key.
 -p passphrase  Provide passphrase.
 -P             Assume empty passphrase.
 -?
 -h             Print this help text.
 -q             Suppress the progress indicator.
 -1             Convert a SSH 1.x key.
 -i file        Load and display information on `file'.
 -D file        Derive the public key from the private key 'file'.
 -B number      The number base for displaying key information (default 10).
 -V             Print ssh-keygen version number.
 -r file        Stir data from file to random pool.
 -F file        Dump fingerprint of file.

我正在运行 Ubuntu 14.04

【问题讨论】:

【参考方案1】:

根据您的命令输出,我推测您应该将 -C 替换为 -c(小写)。所以再试一次-c:

ssh-keygen -t rsa -b 4096 -c "your_email@example.com"

根据文档,-C 应该提供新评论:

-C评论

提供新评论。

所以,既然您的输出显示提供评论,我想它应该适用于-c


您也可以尝试使用ssh-keygen -t rsa


原来ssh-keygen实际上被覆盖了:

我想通了,由于某种原因,我的 /usr/local/bin 中有另一个 ssh-keygen 二进制文件,所以当我使用它时,我使用的是那个,而不是 /usr/bin 中的 ubuntu 附带的那个额外的二进制文件,然后重新安装 Openssh-server 和 openssl 修复了所有问题。谢谢!

【讨论】:

这样做会生成一个不适用于 github 的 ssh2 密钥。此外,在 aws 的情况下,它会自动运行此命令,因此在我使用 ssh 设置项目的过程中失败。 @AdityaBalwani 使用 -C 在我的 Ubuntu 15.04 和我兄弟的 Ubuntu 14.04 上运行良好。这里不知道,除非你可以在另一台机器上生成它并在你的原始机器上复制它。 @AdityaBalwani 尝试使用ssh-keygen -t rsa - 看看是否有帮助 执行ssh-keygen -t rsa 也会生成一个ssh2 密钥。 @AdityaBalwani 我刚刚对其进行了测试,对我来说效果很好。我将它添加到 GitHub 没有问题。如果它不适合你,你可以试试to convert it。

以上是关于无法为 github 和 aws 生成 ssh 密钥(非法选项 -- C)的主要内容,如果未能解决你的问题,请参考以下文章

Linux生成私钥和公钥免密连接

Windows下设置SSH免密

Linux——配置服务器间的免密登录

Linux的SSH免密登录认证过程研究

关于ssh免密互访

Linux服务器 ssh免密登录