git 如何访问我的 SSH 公钥?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3828164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:11:21  来源:igfitidea点击:

How do I access my SSH public key?

gitsshrsa

提问by sscirrus

I've just generated my RSA key pair, and I wanted to add that key to GitHub.

我刚刚生成了我的 RSA 密钥对,我想将该密钥添加到 GitHub。

I tried cd id_rsa.puband id_rsa.pub, but no luck. How can I access my SSH public key?

我试过cd id_rsa.puband id_rsa.pub,但没有运气。如何访问我的 SSH 公钥?

回答by Mitch Dempsey

cat ~/.ssh/id_rsa.pubor cat ~/.ssh/id_dsa.pub

cat ~/.ssh/id_rsa.pub或者 cat ~/.ssh/id_dsa.pub

You can list all the public keys you have by doing:

您可以通过执行以下操作列出您拥有的所有公钥:

$ ls ~/.ssh/*.pub

$ ls ~/.ssh/*.pub

回答by D_D

Copy the key to your clipboard.

将密钥复制到剪贴板。

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

Warning: it's important to copy the key exactly without adding newlines or whitespace. Thankfully the pbcopy command makes it easy to perform this setup perfectly.

警告:在不添加换行符或空格的情况下准确复制密钥很重要。幸运的是 pbcopy 命令可以轻松完美地执行此设置。

And you can paste it wherever you need.

您可以将其粘贴到任何需要的地方。

To get a better idea of the whole process, check this: Generating SSH Keys.

要更好地了解整个过程,请查看:生成 SSH 密钥

回答by kenorb

You may try to run the following command to show your RSA fingerprint:

您可以尝试运行以下命令来显示您的 RSA 指纹:

ssh-agent sh -c 'ssh-add; ssh-add -l'

or public key:

或公钥:

ssh-agent sh -c 'ssh-add; ssh-add -L'

If you've the message: 'The agent has no identities.', then you've to generate your RSA key by ssh-keygenfirst.

如果您收到消息:“代理没有身份。”,那么您必须首先生成您的 RSA 密钥ssh-keygen

回答by nsuinteger

If you're on Windows use the following, select all, and copy from a Notepad window:

如果您使用的是 Windows,请使用以下内容,全选,然后从记事本窗口复制:

notepad ~/.ssh/id_rsa.pub  

If you're on OS X, use:

如果您使用的是 OS X,请使用:

pbcopy < ~/.ssh/id_rsa.pub

回答by Mark

Here's how I found mine on OS X:

这是我如何在 OS X 上找到我的:

  1. Open a terminal
  2. (You are in the home directory) cd .ssh(a hidden directory)
  3. pbcopy < id_rsa.pub (this copies it to the clipboard)
  1. 打开终端
  2. (您在主目录中)cd .ssh(隐藏目录)
  3. pbcopy < id_rsa.pub (这将它复制到剪贴板)

If that doesn't work, do an lsand see what files are in there with a .pubextension.

如果这不起作用,请执行ls并查看其中带有.pub扩展名的文件。

回答by Brett

After you generate your SSH key you can do:

生成 SSH 密钥后,您可以执行以下操作:

cat .ssh/id_rsa.pub |pbcopy

which will copy your ssh key into your clipboard.

这会将您的 ssh 密钥复制到剪贴板中。

回答by avivamg

On terminal cat ~/.ssh/id_rsa.pub

在终端 cat ~/.ssh/id_rsa.pub

explanation

解释

  1. catis a standard Unix utility that reads files and prints output
  2. ~Is your Home User path
  3. /.ssh- your hidden directory contains all your ssh certificates
  4. id_rsa.pubOR id_dsa.pubare RSA public keys, (the private key located on the client machine). the primary key for example can be used to enable cloning project from remote repository securely to your client end point.
  1. cat是一个标准的 Unix 实用程序,用于读取文件并打印输出
  2. ~是你的家庭用户路径
  3. /.ssh- 你的隐藏目录包含你所有的 ssh 证书
  4. id_rsa.pubid_dsa.pub是 RSA 公钥,(位于客户端机器上的私钥)。例如,主键可用于将项目从远程存储库安全地克隆到您的客户端端点。

回答by Riley Taylor

If you are using Windows PowerShell, the easiest way is to:

如果您使用的是 Windows PowerShell,最简单的方法是:

cat ~/.ssh/id_<key-type-here>.pub | clip

That will copy the key to your clipboard for easy pasting.

这会将密钥复制到剪贴板以便于粘贴。

So, in my instance, I use ed25519 since RSA is now fairly hackable:

所以,在我的例子中,我使用 ed25519,因为 RSA 现在相当容易破解:

cat ~/.ssh/id_ed25519.pub | clip


Because I find myself doing this a lot, I created a function and set a simple alias I could remember in my PowerShell profile (learn more about PowerShell profiles here. Just add this to your Microsoft.PowerShell_profile.ps1:

因为我发现自己经常这样做,所以我创建了一个函数并在我的 PowerShell 配置文件中设置了一个我可以记住的简单别名(在此处了解有关 PowerShell 配置文件的更多信息。只需将其添加到您的Microsoft.PowerShell_profile.ps1

function Copy-SSHKey {
    Get-Content ~/.ssh/id_ed25519.pub | clip
}

Set_Alias -Name sshkey -Value Copy-SSHKey

Then, in a PowerShell console, run . $profileto load the functions. Then from now on all you will need to do is run sshkey, and then paste the key into wherever you need via the clipboard.

然后,在 PowerShell 控制台中,运行. $profile以加载函数。然后从现在开始,您需要做的就是运行sshkey,然后通过剪贴板将密钥粘贴到您需要的任何位置。

回答by yavorcik

Use:

用:

# sudo su
# cd /home/user/.ssh
.ssh# gedit id_rsa.pub

Then copy the entire file without any spaces. Click your icon at the top right of the GitHub page, go to settings, and add ssh.

然后复制整个文件,没有任何空格。单击 GitHub 页面右上角的图标,转到设置,然后添加 ssh。

Paste the copy into the space. It may prompt for your GitHub password. Enter it. Save.

将副本粘贴到空间中。它可能会提示您输入 GitHub 密码。输入它。节省。

回答by sbdv0

Open your id_dsa.pub or some_name.pub file with gedit and copy-paste the contents!

使用 gedit 打开您的 id_dsa.pub 或 some_name.pub 文件并复制粘贴内容!

Just use:

只需使用:

~/.ssh$ gedit some_name.pub