gitlab 添加 ssh

git 客户端无法拉取gitlab仓库代码,登陆网页端,查看仓库主页有下面的提示

因此需要添加ssh公钥,才能上传下拉代码

windows平台:

首先需要安装git了。

  1. 在存放代码的目录中,右键选择 “Git Bash Here”  或者 打开命令行
  2. 键入命令: ssh-keygen -t rsa -C "[email protected]"

    "[email protected]是你的gitlab账户邮箱

    $ ssh-keygen -t rsa -C "[email protected]"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa):
  3.  提示需要保存的文件名,提示中已经有文件路径,一般直接回车即可
    /c/Users/xxx/.ssh/id_rsa
    但是如果该文件已存在,最好输入自定义名称,如 id_demo   
  4. 提示输入指纹---直接回车即可
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
  5.  最终的输出信息,

    Your identification has been saved in /c/Users/xxx/.ssh/id_rsa.
    Your public key has been saved in /c/Users/xxx/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:kWcSTzwyl8wMfEvwxxiUBO3o9mpIFH+RRdApHO/CVeo [email protected]
    The key's randomart image is:
    +---[RSA 2048]----+
    |       .=&BXo..  |
    |      . +*^=oo   |
    |       o+O*=*    |
    |      . o*+=     |
    |     . .S.o E    |
    |      . o  .     |
    |     . o .       |
    |      . . .      |
    |       ...       |
    +----[SHA256]-----+

    生成的两个文件路径在  

    /c/Users/xxx/.ssh/id_rsa
    /c/Users/xxx/.ssh/id_rsa.pub
  6.  如果第三步直接回车的,请跳过。 否则,需要将当前目录下的两个文件 id_demoid_demo.pub 复制到 C:\Users\xxx\.ssh 目录下
  7. xxx 是你当前登陆的用户名,可能是Administrator
  8. 用记事本打开id_demo.pub文件,复制内容。在gitlab的网站上到ssh密钥管理页面,添加新公钥,名字默认为邮箱,内容粘贴

如果没有 .ssh 目录,需要使用命令行创建 

 mkdir .ssh

猜你喜欢

转载自www.cnblogs.com/duoxuan/p/10215987.html