简体   繁体   English

Github ssh 密钥 macOS Sierra

[英]Github ssh key macOS Sierra

I've been having problems with gitHub's SSH Key for Mac Sierra here: https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/我在这里遇到了 gitHub 的 Mac Sierra SSH 密钥问题: https ://help.github.com/articles/generate-a-new-ssh-key-and-adding-it-to-the-ssh-agent /

I've been able to follow the steps of我已经能够按照以下步骤操作

  1. ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. eval "$(ssh-agent -s)"

However from this part onwards, nothing works但是从这部分开始,没有任何效果

  1. I do not understand what they mean by "modify your ~/.ssh/config file " & the Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa我不明白他们所说的“修改你的~/.ssh/config文件”和主机 * AddKeysToAgent 是什么意思 UseKeychain 是 IdentityFile ~/.ssh/id_rsa

  2. ssh-add -K ~/.ssh/id_rsa does not work on terminal either, as the results says 'no such file or directory' ssh-add -K ~/.ssh/id_rsa也不适用于终端,因为结果显示“没有这样的文件或目录”

I saved the key file to my Desktop folder when ssh-keygen prompted me for a location.ssh-keygen提示我输入位置时,我将密钥文件保存到我的桌面文件夹中。

When you did an ssh-keygen , you would have been prompted for the location to save the keys in. It is by default ~/.ssh/ .当您执行ssh-keygen ,系统会提示您输入保存密钥的位置。默认情况下是~/.ssh/ If you saved them somewhere else, you should try locate id_rsa and then do ssh-add <path where id_rsa is> .如果您将它们保存在其他地方,您应该尝试locate id_rsa ,然后执行ssh-add <path where id_rsa is>

Move the key to .ssh where it belongs, and/or create a .ssh/config file and tell it where to look for the key.将密钥移动到它所属的.ssh ,和/或创建一个.ssh/config文件并告诉它在哪里查找密钥。

If .ssh doesn't exist, you have to create it first, obviously.如果.ssh不存在,显然您必须先创建它。

# Create ~/.ssh if missing
if ! [ -d "$HOME"/.ssh ], then
    mkdir -p "$HOME"/.ssh
    # Make it private
    chmod 700 "$HOME"/.ssh
fi

# Move files from Desktop
# Assumes id_rsa* matches public and private key files,
# and no others
mv -i "$HOME"/Desktop/id_rsa* "$HOME"/.ssh

# Make them private, too
chmod go-rwx "$HOME"/.ssh/id_rsa*

# Create config file, if missing
test -e "$HOME"/.ssh/config ||
printf '%s\n' 'Host *' \
    '    AddKeysToAgent yes' \
    '    UseKeychain yes' \
    '    IdentityFile ~/.ssh/id_rsa' >"$HOME"/.ssh/config

You can just copy/paste these commands to the Terminal, though putting them in a file like /tmp/sshcommands and running it with bash /tmp/sshcommands might be slightly less jarring.您可以将这些命令复制/粘贴到终端,但将它们放在/tmp/sshcommands类的文件中并使用bash /tmp/sshcommands运行它可能会稍微不那么刺耳。

Obviously, you should read up on these commands enough to understand at least roughly what's going on here.显然,您应该充分阅读这些命令,以至少大致了解这里发生的事情。 Probably the key realization is that ssh doesn't know you have a Desktop folder and would not want to look there for the key even if it knew.可能关键的认识是ssh不知道您有一个Desktop文件夹,即使它知道也不想在那里寻找密钥。 (You could change the final IdentityFile statement to actually change that, but really, at this point you are better off learning the standard practice.) (您可以更改最终的IdentityFile语句以实际更改它,但实际上,此时您最好学习标准做法。)

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

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