GitHub设置添加SSH

一、建立一个新的repository:
github:repository name 和本地建立的git名最好同样
本地:建立文件夹,在文件夹执行命令:git init
 
 
 
二、检查是否已经存在文件id_rsa 或 id_rsa.pub,对外只提供pub(公开)文件:
      在终端执行命令:
cd ~/.ssh

ls

 

 
三、若是已经存在,建立一个 SSH key:
     在终端执行命令:
          
ssh-keygen -t rsa -C "your_email@example.com"

 

"your_email@example.com":是在github找到SHH地址   

接着又会提示你输入两次密码(该密码是你push文件的时候要输入的密码,而不是github管理者的密码),git

固然,你也能够不输入密码,直接按回车。那么push的时候就不须要输入密码,直接提交到github上了,如:github

Enter passphrase (empty for no passphrase): 
# Enter same passphrase again:

接下来,就会显示以下代码提示,如:shell

Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.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
当你看到上面这段代码的收,那就说明,你的 SSH key 已经建立成功,你只须要添加到github的SSH key上就能够了。
 
 
四、添加SSH key到github上
  a、首先拷贝id_rsa.pub 文件的内容,用git命令复制内容,代码以下:
            
clip < ~/.ssh/id_rsa.pub

 

  b、登陆github帐号,右上角选择Sittings进入,点击菜单栏SHH key进入页面添加SHH key
 
  c、Title输入一个该SHH key 显示在github上的一个别名,默认的会使用你的邮件名称,key粘贴a步骤复制的内容 。注意SHH key 代码的先后不要留有空格或者回车。点击Add SHH key按钮添加一个SSH key。
 
 
五、测试一下该SHH key
     在终端输入如下代码:
 
shh -T git@github.com

 

当你输入以上代码,会有一段警告代码,如:
     
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 回车便可。若是你建立SSH key的时候设置了密码,接下来会提示你输入密码,如:
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
 
 
输入正确密码以后你会看到如下内容:
Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
 
若是username显示的你正确的用户名,表示你已经成功设置SSH key,若是你看到“access denied”,则表示拒绝访问,那你就要使用https去访问,而不是SSH。
 
 
 
 
六、上传内容步骤,一次输入代码:
     
git add 文件名

git commit -m "上传说明"

git push origin master

 

若是出现如下内容:
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
 
Please make sure you have the correct access rights
and the repository exists.
 
说明尚未添加origin,因此就要执行如下代码:
git remote add origin "SHH 地址"

git push origin master
就能够上传成功了。
相关文章
相关标签/搜索