美文网首页
git生成SSH Key,生成多个SSH key

git生成SSH Key,生成多个SSH key

作者: arik2020 | 来源:发表于2019-10-10 11:30 被阅读0次

    当我们使用github或者bitbucket等仓库时我们有可能需要ssh认证,所以需要生成他的ssh key。

    git生成SSH Key

    1、首先你要安装git工具

    下载地址:https://git-scm.com/downloads

    2、右键鼠标,选中 “Git Bash here”,当然你也可以在windows的 “开始”--->“所以程序”,或者安装目录打开它

    3、输入如下指令 ,进入.ssh文件夹

    $ cd ~/.ssh/
    

    如果提示 “ No such file or directory”,你可以手动的创建一个 .ssh文件夹即可,命令为:

    $ mkdir ~/.ssh
    

    4、配置全局的name和email,这里是的你github或者bitbucket的name和email

    $ git config --global user.name "你的用户名"
    
    $ git config --global user.email "你的公司或个人邮箱"
    

    5、生成key

    $ ssh-keygen -t rsa -C "你的公司或个人邮箱"
    
    

    连续按三次回车,这里设置的密码就为空了,并且创建了key。

    最后得到了两个文件:id_rsa和id_rsa.pub

    6、打开Admin目录进入.ssh文件夹,用记事本打开id_rsa.pub,复制里面的内容添加到你github或者bitbucket ssh设置里即可

    生成多个SSH key

    1、生成SSH key,并指定文件名,避免覆盖原有的默认id_rsa文件。

    $ ssh-keygen -t rsa -f ~/.ssh/id_rsa.another -C <Git注册邮箱>
    

    2、配置config文件

    在~/.ssh下添加config文件,如果已经存在,就直接打开修改。

    $ touch ~/.ssh/config   // 创建
    

    在config文件中添加如下信息。其中Host后面添加远程Git仓库域名,IdentityFile填写对应的id_rsa文件,User添加Git用户名。

    Host github.com
        IdentityFile ~/.ssh/id_rsa.another
        User anotherUser
    

    相关文章

      网友评论

          本文标题:git生成SSH Key,生成多个SSH key

          本文链接:https://www.haomeiwen.com/subject/yxjgyctx.html