美文网首页web前端杂文
多域名 ssh git 配置

多域名 ssh git 配置

作者: 文优 | 来源:发表于2016-09-27 12:58 被阅读500次

    ssh 公钥生成

    生成, 默认文件名为id_rsa

    ssh-keygen -t rsa -C "your_email@example.com"
    

    多个key的情况, second为文件名称

    ssh-keygen -t rsa -C "your_email@example.com" -f ~/.ssh/second
    

    服务端配置

    将生成的xxx.pub的内容拷贝到对应的网站中


    ssh config 配置. ~/.ssh/config

    • Host >域名
    • User >用户名
    • IdentityFile >ssh key的路径
    • IdentitiesOnly >只使用这里设置的key, 防止使用默认的
    • ServerAliveInterval >连接保持
    • ControlMaster auto >不用重新登录
    • ControlPath ~/.ssh/master-%r@%h:%p
    Host github.com
        User git
        IdentityFile ~/.ssh/id_gmail
        IdentitiesOnly yes
    Host bitbucket.org
        User git
        IdentityFile  ~/.ssh/id_gmail
        IdentitiesOnly yes
    Host git.coding.net
        User git
        IdentityFile ~/.ssh/id_gmail
        IdentitiesOnly yes
    Host git.oschina.net
        User git
        IdentityFile ~/.ssh/id_gmail
        IdentitiesOnly yes
    Host *.alibaba-inc.com
        User git
        IdentityFile ~/.ssh/id_rsa
    Host *
        ServerAliveInterval 60
        ControlMaster auto
        ControlPath ~/.ssh/master-%r@%h:%p
    

    保存

    ssh-add -K ~/.ssh/id_gmail
    

    连接测试

    ssh -T git@github.com
    

    git 名称设置

    git config --global user.name "User name"
    git config --global user.email user@example.com
    

    如果不设置全局的, 在项目目录下执行, 去掉--global即可

    相关文章

      网友评论

        本文标题:多域名 ssh git 配置

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