如何生成git 仓库SSH key

  1. 检查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
  1. 生成新的SSH key
在命令行中输入ssh-keygen -t rsa -C "[email protected]"

将新生成的key添加到ssh-agent中:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa
  1. 将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

你可能感兴趣的:(如何生成git 仓库SSH key)