如何在Mac下配置Github和Bitbucket的SSH

版权声明:本Blog内文章为网络自学笔记,个别内容及图片引用自网络,如有侵权请联系本人,本人将会在第一时间删除侵权内容。欢迎各位朋友评论交流! https://blog.csdn.net/Zhangxichao100/article/details/78901123

title: 如何在Mac下配置Github和Bitbucket的SSH
date: 2017-12-23 21:10:30
tags:
- Mac
- Git
- Github

categories: Github

如何在Mac下配置Github和Bitbucket的SSH

第一步:生成 SSH 公钥过程

大多数 Git 服务器都会选择使用 SSH 公钥来进行授权。系统中的每个用户都必须提供一个公钥用于授权,没有的话就要生成一个。生成公钥的过程在所有操作系统上都差不多。

1.查看是否已经有了SSH密钥

首先先确认一下是否已经有一个公钥了。SSH 公钥默认储存在账户的主目录下的 ~/.ssh 目录。进去看看:

cd ~/.ssh

如果没有密钥则不会有此文件夹,有则备份删除

cp -R ~/.ssh ~/.ssh_bak
rm -R ~/.ssh  

2.生成密钥

ssh-keygen -t rsa -C "你在Github上的邮箱"

第一次要输入file名字,直接回车即可,默认文件名为id_前缀,然后会被要求输入个密码并且确认。

第二步:添加密钥到SSH

cd ~/.ssh
ssh-add -K id_rsa

需要刚才生成密钥时候输入的密码。

在github上添加SSH Key

more id_rsa.pub
  • 查看公钥里的内容并且全部复制下来(包括开头ssh-rsa和结尾邮箱)。
  • 进入到githubsetting,找到SSH Keys页面添加一个key,title随意,赋值公钥进去保存即可。

第三步:测试是否成功

ssh [email protected]

成功则返回类似:

Hi Seachal! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Bitbucket

Bitbucket.org是一个和Github极其类似的托管库网站,但是他的私有库是免费的,所以一般我们会把私有库放到bitbucket上,而其他库放到github上,毕竟githubSNS属性稍微多些,开源的库就尽量的希望有与其他人的更多互动。
bitbucket添加SSH Key实际上是一样的。
测试bitbucket ssh是否可连接

ssh -T [email protected]

成功则返回类似:

logged in as Seachal.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

1b56d6e0122ce0f0105bb1b4d61b7b68

猜你喜欢

转载自blog.csdn.net/Zhangxichao100/article/details/78901123