GitHub/Bitbucket 通过 SSH 密钥连接

Step 1: 检查SSH密钥

cd ~/.ssh  

如果返回 “No such file or directory” 转 Step 2. 否则说明你已经有一个密匙对,转到 Step 3.

Step 2-1: 生成新的SSH密钥

ssh-keygen -t rsa -C "your_email@example.com"  

使用你的邮件创建一个新的 SSH 密匙标签,将会生成 ~/.ssh/id_rsa 文件, 用于存储你的密匙。

现在,你需要输入一个密码:

Enter passphrase (empty for no passphrase): [输入一个密码]  

Enter same passphrase again: [重新输入密码]  

一般没有特殊需要,直接回车即可。

你将看到一下信息:

Your identification has been saved in /home/userName/.ssh/id_rsa.  
Your public key has been saved in /home/userName/.ssh/id_rsa.pub.  
The key fingerprint is:  
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

Step2-2

add your new key to the ssh-agent:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add ~/.ssh/id_rsa

Step 3-1: 复制 SSH 密匙

使用 cat 命令

cat ~/.ssh/id_rsa.pub  

输入到终端再复制。

Step 3-2: 添加 SSH 密匙到 GitHub

  1. 点击右上角 "Account Settings" 设置图标

  2. 点击左侧 "SSH Keys"

  3. 点击 "Add SSH key"

  4. 粘贴你的密匙到 "Key" 文本区

  5. 点击 "Add key"

  6. 确认操作输入你的 GitHub 密码

Step 3-3: 添加 SSH 密匙到 Bitbucket

  1. 点击右上角"用户头像"

  2. 点击下拉菜单中的 "Manage account"

  3. 点击左侧 "SSH keys"

  4. 点击 "Add key"

  5. 粘贴你的密匙到 "Key" 文本区

  6. 点击 "Add key"

Step 4: 测试连接

GitHub:

ssh -T git@github.com  

Bitbucket:

ssh -T git@bitbucket.org  

你可能会看到这样的提示:

The authenticity of host 'github.com (207.97.227.239)' 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)?

输入 yes 即可

GitHub 成功提示:

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

Bitbucket 成功提示:

conq: logged in as userName.  
You can use git or hg to connect to Bitbucket. Shell access is disabled.

如果出现 access denied 一般是添加的 key 的问题,请检查本地 key 和线上 key 是否相同, 或参考 Error: Permission denied (publickey)。

到此你就可以使用 git clone 你的项目,提交更改了。

转载于:https://my.oschina.net/jonetwelve/blog/617059

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值