简体   繁体   English

如何验证 github SSH 密钥

[英]How to verify github SSH key

I want to verify that my SSH key in github matches the local file on my computer.我想验证我在 github 中的 SSH 密钥是否与我计算机上的本地文件匹配。

在此处输入图像描述

The github key seems to be SHA256, encoded in base64, but my local key, encoded with this command doesn't seem to match it. github 密钥似乎是 SHA256,以 base64 编码,但我的本地密钥,用此命令编码似乎与它不匹配。

$ cat ~/.ssh/github.pub | sha256sum | base64

Is there a better way to achieve what I'm trying to do?有没有更好的方法来实现我想要做的事情?

A simple way to test that they match is by authenticating by ssh in the command line.测试它们是否匹配的一种简单方法是在命令行中通过 ssh 进行身份验证。

After setting up your ssh-key, type:设置好 ssh-key 后,输入:

ssh -T git@github.com

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection

An SSH public key in OpenSSH format contains two or three parts, separated by spaces: OpenSSH 格式的 SSH 公钥包含两个或三个部分,以空格分隔:

  • The algorithm name.算法名称。
  • A base64-encoded SSH public key in protocol format.协议格式的 base64 编码 SSH 公钥。
  • An optional comment.可选注释。

The fingerprint of an SSH key is the base64-encoded SHA-256 hash of the raw public key (that is, without the base64 encoding). SSH 密钥的指纹是原始公钥的 base64 编码的 SHA-256 hash(即没有 base64 编码)。 You can script this, but fortunately, there's an easy way to find it out using ssh-keygen :您可以编写此脚本,但幸运的是,有一种简单的方法可以使用ssh-keygen找到它:

$ ssh-keygen -l -f ~/.ssh/id_ed25519.pub

You can change the file name for the public key to the appropriate one on your system.您可以将公钥的文件名更改为系统上的相应文件名。 On my system, the output looks like this:在我的系统上,output 看起来像这样:

256 SHA256:E59Xzh/fsZKkCEL46kTLbPFGXyIodA+ntsQL0JWmq9Y bmc@camp (ED25519)

The fingerprint is the second piece.指纹是第二块。

This one will use only the key supplied in -i for auth:这将仅使用-i中提供的密钥进行身份验证:

ssh -i ~/.ssh/github -o IdentityAgent=none -T git@github.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM