当你在Git代码库房,比方Github或者国内的码云Gitee,创建了一个库房后,相关本地文件,或许呈现以下情况:

  • 库房初始化
$ git commit -m "init page"
[master (root-commit) d832761] init page
 1 file changed, 7 insertions(+)
 create mode 100644 index.html
  • 相关本地文件
$ git remote add origin git@github.com:xxxxx/xxxxx.github.io.git
  • push remote库房
$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
  • 失败,被奉告没有访问权限,这是由于本机没有给代码库房装备密匙
  • 开始放大招,执行命令ssh-keygen -t rsa -C 你的邮箱地址,获取public 密匙
$ ssh-keygen -t rsa -C 你的邮箱地址
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
2c:03:89:09:5c:4c:2a:b9:2b:bd:ec:2b:a0:ce:ff:22 xxxxxxxxxx@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
|o +o             |
| +.+ .           |
|o.o o            |
|..   . .         |
|.     o S        |
|.o     o         |
|= .              |
|=E o             |
|.=Boo.           |
+-----------------+
  • 依据途径找到id_rsa.pub文件,仿制里边的内容,这儿演示粘贴到Github的personal settings的SSH keys中

1827449-003ca9ff10413ba8.webp

  • 再一次push提交代码,成功,well done
$ git push -u origin master
Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa':
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:xxxxx/xxxxx.github.io.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.