Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAC添加GitHub SSH验证 #37

Open
Myoursky opened this issue Aug 8, 2018 · 0 comments
Open

MAC添加GitHub SSH验证 #37

Myoursky opened this issue Aug 8, 2018 · 0 comments
Labels

Comments

@Myoursky
Copy link
Owner

Myoursky commented Aug 8, 2018

MAC添加GitHub SSH验证

查看本地是否已经存在SSH文件

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

生成SSH KEY

ssh-keygen -t rsa -b 4096 -C "[email protected]"

-C后面是生成的公有key标识,可以随意写。
生成的文件默认路径是/Users/you/.ssh/id_rsa,此处会询问是否添加密码,我直接跳过了。
you是你电脑的用户名。

添加SSH KEY到ssh-agent

因为我电脑版本是 macOS Sierra 10.12.6,所以直接通过~/.ssh/config管理。
在config中添加以下配置

# github server
# HOST是别名
Host github
# github地址
HostName github.com
# 此处直接填git
User git
# 私有key
IdentityFile ~/.ssh/id_rsa

添加本地公有key到github

复制id_rsa.pub的内容,在github的Setting > SSH and GPG keys > SSH keys按钮下新建一个SSH key,
并将内容粘贴到Key输入框中。至此所有操作完成。

测试SSH连接

ssh -T [email protected]
# Attempts to ssh to GitHub

如果看到以下警告

The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
The authenticity of host 'github.com (IP ADDRESS)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?

则输入yes。

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

看到以上提示信息表示连接成功。

此时clone或者提交代码时就不需要再输入密码了。但是要注意的是,clone的代码请选择Clone With SSH

详细教程
官网

@Myoursky Myoursky added the tools label Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant