如何生成SSH key

第一步,检查本机是否存在

输入下面的命令,如果有文件id_rsa.pub 或 id_dsa.pub,则直接进入步骤3将SSH key添加到GitHub中,否则进入第二步生成SSH key

$ ls -al ~/.ssh
total 56
drwxr-xr-x 1 Administrator 197121    0 八月 26 10:52 ./
drwxr-xr-x 1 Administrator 197121    0 八月 26 11:08 ../
-rw-r--r-- 1 Administrator 197121 1675 八月 26 10:54 id_rsa
-rw-r--r-- 1 Administrator 197121  398 八月 26 10:54 id_rsa.pub
-rw-r--r-- 1 Administrator 197121  973 八月 26 08:33 known_hosts
drwxr-xr-x 1 Administrator 197121    0 八月 26 10:52 秘钥备份/

2. 生成新的ssh key(旧的也许不是你账号的秘钥,直接覆盖掉)

第一步:
在命令行中输入ssh-keygen -t rsa -C "[email protected]"

默认会在相应路径下(/c/Users/Administrator/.ssh/id_rsa)生成id_rsaid_rsa.pub 、known_hosts三个文件,如下面代码所示

$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
/c/Users/Administrator/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
SHA256:X.........................oo [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|       o .       |
|      = +        |
|     . * o       |
|  o o = S .      |
| = = = + .       |
|o B = + o        |
|o= = =B=.*       |
|E.o [email protected]      |
+----[SHA256]-----+

第二步:输入passphrase(本步骤可以直接按回车跳过)

设置passphrase后,进行版本控制时,每次与GitHub通信都会要求输入passphrase,以避免某些“失误”

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

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

ssh-add ~/.ssh/id_rsa

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa

3. 将ssh key添加到 码云 或者GitHub中

打开id_rsa.pub文件,里面的信息即为SSH key,直接复制出来添加到ssh管理即可

如何生成SSH key_第1张图片

 

 

 

你可能感兴趣的:(android开发基本)