问题背景
小组使用GitLab管理工程和代码,使用git通过ssh方式克隆某项目时,
提示如下信息
git clone ssh://git@182.48.110.196:10022/../tflite_yolov3.git
Cloning into 'tflite_yolov3'...
The authenticity of host '[182.48.110.196]:10022 ([182.48.110.196]:10022)' can't be established.
ECDSA key fingerprint is SHA256:4v21q2IKK1YTjezwWwSzAAR/OS0IANbxYVnVj/l1BVI.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[182.48.110.196]:10022' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
其中
Cloning into 'tflite_yolov3'...
The authenticity of host '[182.48.110.196]:10022 ([182.48.110.196]:10022)' can't be established.
ECDSA key fingerprint is SHA256:4v21q2IKK1YTjezwWwSzAAR/OS0IANbxYVnVj/l1BVI.
Are you sure you want to continue connecting (yes/no)?
询问本机是否要连接远程服务器,选yes表示同意和远程服务器建立联系。
其中
Warning: Permanently added '[182.48.110.196]:10022' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
表示本机对应的公钥没有在远程仓库列表,不能下载远程仓库代码。需要将代表本机的公钥上传到gitlab账户。
配置ssh key(一对钥匙,一个是公钥,另一个是私钥)
第一步:配置用户名和邮箱
首先用如下命令(如未特别说明,所有命令均默认在Git Bash工具下执行)检查一下用户名和邮箱是否配置。若有内容表示已配置,若无内容表示未配置。
git config -l
若未配置,通过下面命令配置用户名和邮箱(根据自己实际用户名和邮箱设置,下面仅是示例)。因为Git是分布式版本控制系统,每个机器都必须自报家门:你的名字和Email地址,可以认为是每个机器的身份证IP。
git config --global user.name "wangerya"
git config --global user.email "王二丫@qq.com"
注意git config命令的–global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。
生成后,再次通过命令查看是否已成功配置
git config -l
第二步:生成ssh key
执行以下命令生成秘钥:
ssh-keygen -t rsa -C "王二丫@qq.com"
键入命令后,会让你输入密码用来保护你的密钥等,总共三次需要输入的,你都直接三次回车就好!!
【关键是,设置了你自己以后忘了就得重新生成】
【-C 是给你的密钥设置注释,你不想设置为邮箱,设置成别的也行】
在指定的保存路径()下会生成2个名为id_rsa和id_rsa.pub的文件,分别对应私钥和公钥。打开公钥,复制内容。
默认保存路径查看如下
第三步:上传公钥
打开gitlab账户设置页面,粘贴到gitlab账户即可。