关于git:git配置多个SSHKey

61次阅读

共计 520 个字符,预计需要花费 2 分钟才能阅读完成。

咱们在日常工作中会遇到同一台服务器部署多个放在 github 上的利用,这样咱们就须要配置不同的 ssh-key 对应不同的环境。

1, 生成 ssh-key

ssh-keygen -t rsa -C 'youremail@your.com' -f ~/.ssh/xxx_rsa

2,将 xxx_rsa.pub 中的内容增加到本人的 github 中。

cat ~/.ssh/xxx_rsa.pub

3,增加到 github

4,进入到~/.ssh 目录下新建 config 文件,用编辑器关上 config 文件并增加内容

# xx1 我的项目
Host github-tm.com # 拜访 git 网址的域名
    HostName github.com # git 官网地址,都是 github.com
    User git
    IdentityFile /root/.ssh/id_rsa # rsa 绝对路径

# xx2 我的项目
Host github-dk.com
        HostName github.com
        User git
        IdentityFile /root/.ssh/xiaoke_rsa

5,测试

ssh -T git@github-xxx.com

6,Git 命令 clone 我的项目

git clone git@github-xxx.com:leadson/xxx.git

正文完
 0