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
点击右上角 "Account Settings" 设置图标
点击左侧 "SSH Keys"
点击 "Add SSH key"
粘贴你的密匙到 "Key" 文本区
点击 "Add key"
确认操作输入你的 GitHub 密码
Step 3-3: 添加 SSH 密匙到 Bitbucket
点击右上角"用户头像"
点击下拉菜单中的 "Manage account"
点击左侧 "SSH keys"
点击 "Add key"
粘贴你的密匙到 "Key" 文本区
点击 "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 你的项目,提交更改了。