yang@yang MINGW64 ~
$ cd ~ //进入家目录
yang@yang MINGW64 ~
$ rm -r .ssh //删除原先的目录.ssh
rm: cannot remove '.ssh': No such file or directory
yang@yang MINGW64 ~
$ ssh-keygen -t rsa -C 907486852@qq.com //生成公钥、私钥
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/yang/.ssh/id_rsa):
Created directory '/c/Users/yang/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/yang/.ssh/id_rsa.
Your public key has been saved in /c/Users/yang/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pPSUKaoux0qw9t66ynPdkt2FOn0vNISfZx+v6H5MAIE 907486852@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| ... |
| Eo. |
| o = .. |
| o * . .. |
|. . . S + .. |
|.. . . * o.. |
|.+. . + + o +o. o|
|=o+..+ = o o .o..|
|.**=o.. . .o*o.. |
+----[SHA256]-----+
yang@yang MINGW64 ~
$ cd .ssh/
yang@yang MINGW64 ~/.ssh
$ ll
total 5
-rw-r--r-- 1 yang 197121 1679 10月 23 09:12 id_rsa
-rw-r--r-- 1 yang 197121 398 10月 23 09:12 id_rsa.pub
yang@yang MINGW64 ~/.ssh
$ cat id_rsa.pub //获取公钥并复制
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZQfyIhOvVKgmO0aFWGevGHfHx1o4eD2lvZWviJR8VKBDl0bKMD/bjA9Iv6+VkWiFCMQsUGmXBHAPOtB0uvE3feAsDIePCxP1LeeV7CMHLUH04TS7kO+zj99kJddkyGwMejBdnD1rh3UDGn1qDL40G1SFxZnm+AnDH7eO0G9rmEcln4BEhk5Ug5QoTe1td/4vdZtWe9vL0EOPHKi4c/H4+iewTsSISXUvD3SBXZhdp2FnMhtpHa7VHgC0sn+P7T2/Z4UGZZZEfXD0/+xznlAran2xkVZuNnPlvpfkyUkGzMO9CBzzpApMEENfbLs2Byh3ShzIMqKnJR5eHaE+JyEWn 907486852@qq.com
2、服务器端配置公钥
3、验证免密登录
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ vim test.txt //编辑文件
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git add test.txt //暂存
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git commit -m "test ssh for remote" test.txt //提交到本地库
[master a4f04be] test ssh for remote
1 file changed, 2 insertions(+)
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git remote -v //查看远程库地址及别名
origin https://github.com/907486852/weChat.git (fetch)
origin https://github.com/907486852/weChat.git (push)
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git remote add origin_ssh git@github.com:907486852/weChat.git //为ssh地址添加别名
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git remote -v //查看远程库地址
origin https://github.com/907486852/weChat.git (fetch)
origin https://github.com/907486852/weChat.git (push)
origin_ssh git@github.com:907486852/weChat.git (fetch)
origin_ssh git@github.com:907486852/weChat.git (push)
yang@yang MINGW64 /d/GitWorkSpace/weChat (master)
$ git push origin_ssh master //推送到origin_ssh master分支
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 246 bytes | 61.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:907486852/weChat.git
3eebe6e..a4f04be master -> master