- 检查SSH key
输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则直接进入步骤3将SSH key添加到Git仓库中,否则进入第二步生成SSH key
ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist
- 生成新的SSH key
在命令行中输入ssh-keygen -t rsa -C "your_email@example.com"
将新生成的key添加到ssh-agent中:
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa
- 将ssh key添加到Git 仓库里边
输入如下命令直接将SSH key复制到粘贴板中
mac
pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
windows
clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
linux
sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard