赞
踩
git使用SSH配置, 初始需要以下三个步骤
Step 1: 核验本地主机是否已经存在ssh密钥。(若id_rsa和id_rsa.pub文件存在,说明已经存在SSH key密钥,反之,需要生成新密钥)
- Maxwell Pan@MaxwellPan MINGW64 ~
- $ cd ~/.ssh
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ls
- known_hosts
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
如果不存在ssh key,使用如下命令生成
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ssh-keygen -t rsa -C "xxxxxxxx@xxx.com"
- Generating public/private rsa key pair.
- Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
- Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
- The key fingerprint is:
- SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 xxxxxxx@xxx.com
- The key's randomart image is:
- +---[RSA 3072]----+
- |o.+oo |
- |.o.o.. . |
- |oo o++ |
- |...o.++o. |
- |=.oo..+=S |
- |.=.=o.*.. |
- |.E=+oo + |
- |oo+.= . |
- |==oo o |
- +----[SHA256]-----+
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ls
- id_rsa id_rsa.pub known_hosts
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
生成完以后再用第二步命令,查看ssh key
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ls
- id_rsa id_rsa.pub known_hosts
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ cat id_rsa.pub
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjxxxxxxxxxxxxxxxxxGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA07qygQLEzUItDRMNfLT5UpYTjBk/RqFbB9KpGTtkH9B++lLC6nosN1dwLugEdW05P+SGfay3xlFmc7+f/lgP3xxxxxxxxxxxxxxxxxxxxx80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= xxxxxxxxx@xxxx.com
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
复制cat 的内容到Github账号上去 设置密钥。首先点击头像下的setting , 找到SSH and GPG keys这个栏位。点击 New SSH key,将上面cat出来的内容添加到New SSH key,并取个名字。
Step 4 : 验证 配置密钥是否成功。
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ssh -T git@github.com
- Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $
设置成功后,即可不需要账号密码clone和push代码
以下为全过程:
- Maxwell Pan@MaxwellPan MINGW64 ~
- $ cd ~/.ssh
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ls
- known_hosts
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ssh-keygen -t rsa -C "xxxxxxxx@qq.com"
- Generating public/private rsa key pair.
- Enter file in which to save the key (/c/Users/Maxwell Pan/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa
- Your public key has been saved in /c/Users/Maxwell Pan/.ssh/id_rsa.pub
- The key fingerprint is:
- SHA256:QqppfBW5oA8VAGjWSTouObN23WwhnVowrLbPGLreok4 xxxxxxxxxx@qq.com
- The key's randomart image is:
- +---[RSA 3072]----+
- |o.+oo |
- |.o.o.. . |
- |oo o++ |
- |...o.++o. |
- |=.oo..+=S |
- |.=.=o.*.. |
- |.E=+oo + |
- |oo+.= . |
- |==oo o |
- +----[SHA256]-----+
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ls
- id_rsa id_rsa.pub known_hosts
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ cat id_rsa.pub
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDFWXsAPl4sGCgRjTSVOZlxfv2ZWYBteE0gYdmN6A8teeUkh6WCsbqyVtUUNkaaUC9Zpn0xUb8hpMr9Cbhiyy90D2mIuxK37RQWi4mz5PSGIXZ/tNQ/n8oFNrhmAx7ljWmFxvmMB4CVIUCujpYunj6P8vBZaIrR5+Rakec8gjvxxxxxxxxxxxxaw6YoE1qrGllKPpuVa9f4KjRet0BRXg4oiXE8DB6bODsAjSnBrYlf3Cj3EyhQyA0xxxxxxxxxk/RqFbB9KpGTtkH9B++lLC6nosN1dwLxxxxxxxxxFmc7+f/lgP3bTb9egBjTpYqRC48fwOtYqbmP2HN0wX+9T0c4+9X80u9mA2RNDz1gqji1sL6K0IdbmqJ7vOi/xBfPs3kswVZxoDiWr8Bh4/xYRYm53rORPLWvMN+AQlCLVq9GlYb2y2mN37PU5qUjs3INzPE9TV1F4EhMl2E5DQhHcbMmILwyqe9+8= xxxxxxxxxxx@qq.com
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $ ssh -T git@github.com
- Hi psmaxwell! You've successfully authenticated, but GitHub does not provide shell access.
-
- Maxwell Pan@MaxwellPan MINGW64 ~/.ssh
- $
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。