简体   繁体   English

新终端中的公钥被拒绝

[英]public key denied in new terminal

I generated a ssh key and set it up on bitbucket and all was good but when I restarted my computer the key was now getting permission denied.我生成了一个 ssh 密钥并将其设置在 bitbucket 上,一切都很好,但是当我重新启动计算机时,密钥现在被拒绝许可。 I remade it and it failed again when I used a new terminal window.我重做了它,但当我使用新的终端 window 时它又失败了。 I'm on windows if that helps.如果有帮助,我在 windows 上。

在此处输入图像描述

在此处输入图像描述

This is normally happens based on what OS you're using and can be for a couple of reasons.这通常取决于您使用的操作系统,并且可能有几个原因。

  1. Your shell/terminal don't initialize an SSH Agent at launch您的外壳/终端不会在启动时初始化 SSH 代理
  2. Your OS/terminal don't load the default private key at lunch您的操作系统/终端不会在午餐时加载默认私钥
  3. There's also this edge case if you rename the private key it will no longer know how to load it.如果您重命名私钥,也会出现这种极端情况,它将不再知道如何加载它。

The easiest fix is to add the following lines to your ~/.profile , ~/.bash_profile or ~/.zshrc .最简单的解决方法是将以下行添加到您的~/.profile~/.bash_profile~/.zshrc中。

eval $(ssh-agent) # create a agent for the shell
ssh-add ~/.ssh/id_rsa # this is one of the default file names, changes as required

Windows also support a similar way for Git Bash. Windows 也支持 Git Bash 的类似方式。

This should load your key to the shell at each lunch or tab.这应该在每个午餐或标签上加载您的 shell 的密钥。

Ps: If your private key has a password, it will prompt for you to type the password every time this runs. ps:如果你的私钥有密码,每次运行都会提示你输入密码。

This is what it would look like when you launch Git Bash这就是您启动 Git Bash 时的样子

Agent pid 16516
Identity added: /c/Users/Praveen/.ssh/id_rsa (/c/Users/Praveen/.ssh/id_rsa)

Praveen@DESKTOP MINGW64 ~/Desktop
$

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

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