IDEA 中git使用非默认ssh客户端进行登录,


IDEA 中git使用非默认ssh客户端进行登录

一、创建多对ssh秘钥对

  1. Mac 版在终端中 Windows 版 在git bash 中创建
  2. 使用ssh-keygen 创建秘钥对 -t 指定秘钥类型 -C 为备注 一般使用邮箱为区分
  3. 生成的文件 Mac ~/.ssh/ 目录下 Windows 一般在执行目录下
  4. 重复以上步骤生成多对秘钥即可
# ssh-keygen -t rsa -C "xxxx@xxx.com" 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/alan/.ssh/id_rsa): test_rsa  ---生成key的名称
Enter passphrase (empty for no passphrase):
Enter same passphrase again:   输入两边密码 或者直接回车无密码

二、设置非默认位置的秘钥在git中使用

  1. 用户目录下的.ssh文件夹中创建文件 config Mac 在终端输入 cd ~/.ssh 即可 Windows 自行理解
  2. 编辑config文件
Host git.xxx.com
     HostName 你要代理的域名、ip地址等
     IdentityFile 绝对路径的 test_rsa

三、在IDEA的git中应用

  1. 将git连接地址由 git@xxx.com:xxx/xxx.git 更改为 git@git.xxx.com:xxx/xxx.git
  2. 将test_rsa.pub 内容添加到git SSH公钥库
  3. 更新git url命令如下
# git remote set-url origin  新地址

相关内容