//本环境为os下
//首先是查看本机安装git版本
yangliu$ git --version
git version 2.17.0
//git目录
yangliu$ which git
/usr/local/bin/git
//生成git用户名和邮箱
yangliu$ git config --global user.name "renyu" //里面是自己的用户名
yangliu$ git config --global user.email "ren**@163.com" //里面是自己的邮箱
//查看是否已经有密钥,我这里之前没有,有的话用就可以咯
yangliu$ cd ~/.ssh
-bash: cd: /Users/yangliu/.ssh: No such file or directory
//生成根,输入下面的命令后 三个回车,其中有输入密码,这里有一步就是密码为空
yangliu$ ssh-keygen -t rsa -C "ren****@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/yangliu/.ssh/id_rsa): //生成的id_rsa公钥
Created directory '/Users/yangliu/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/yangliu/.ssh/id_rsa.
Your public key has been saved in /Users/yangliu/.ssh/id_rsa.pub.//生成的公钥地址
The key fingerprint is:
SHA256:******* ren*****@163.com
The key's randomart image is:
+---[RSA 2048]----+
| . .|
| o . o.|
| o . o.o|
| . o .o .o.|
| + S oo =o |
| . o .X+ o |
| . Bo.*o+|
| . *.O=+o=|
| E o.**B oo|
+----[SHA256]-----+
//查看生成的公钥
yangliu$ cd /Users/yangliu/.ssh/
yangliu$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHqIyXu2BcSU3OYWdx3rLTYe3UlX03BOrSjs91TYCXh**************************************** [email protected]
//测试github
yangliu$ ssh [email protected]
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:************.
Are you sure you want to continue connecting (yes/no)? yes//输入
Warning: Permanently added 'github.com,13.250.*.*' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi sharoA! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
可以把生成的公钥放到github上就可以上传到他那里啦 ,也可以添加到你们公司的authorized_keys上。