IDEA 配置SSH 方式访问 GIT

  • 生成公私钥
  • 配置 GITLAB 代码仓库的域名映射和端口(可选)
  • 配置 GITLAB
  • IDEA 配置 SSH 登陆


文章标签:SSH 方式访问 GIT、IDEA 配置免密登陆、GITLAB 配置免密

系统介绍:Windows10 + IDEA 2020.3 + GIT + GITLAB

一般公司用的都是 GITLAB,所以配置大致相同,该文档介绍的配置是通过 SSH 方式访问,HTTP 方式访问相对简单些,请对号入座,如有问题,请留言

生成公私钥

此处已经忽略安装 GIT ,自行百度查看各个系统的 GIT 的安装教程

① 打开 GITBash 窗口,输入以下命令,连续按 3 次回车

ssh-keygen -t rsa

idea配置ssh隧道mysql idea配置ssh隧道_代码仓库


② 查看生成的公私钥文件

# Windows 下的公私钥文件路径
C:\Users\用户名\.ssh

# Linux 下的公私钥文件路径
/home/用户名/.ssh

# Macos 下的公私钥文件路径	
/Users/用户名/.ssh

idea配置ssh隧道mysql idea配置ssh隧道_文件路径_02


如果没有看到生成的文件或者文件名称不对,请确认文件是否拓展名被隐藏了

idea配置ssh隧道mysql idea配置ssh隧道_idea配置ssh隧道mysql_03


idea配置ssh隧道mysql idea配置ssh隧道_idea配置ssh隧道mysql_04

配置 GITLAB 代码仓库的域名映射和端口(可选)

注意:如果公司的代码仓库的域名需要映射或者修改端口,需要做这个步骤,否则就跳过,一般都跳过该步骤
① 在 .ssh 目录下创建名称为 config 的文件,该文件没有后缀,可以在此处通过 Git Bash 创建

idea配置ssh隧道mysql idea配置ssh隧道_代码仓库_05


idea配置ssh隧道mysql idea配置ssh隧道_idea配置ssh隧道mysql_06

② 编辑 config 文件,格式如下,按照自己公司的进行配置

Host xx.xx.xx.xx
Port xxxx

配置 GITLAB

① 配置公钥

idea配置ssh隧道mysql idea配置ssh隧道_文件路径_07

② 将生成的公钥文件 id_rsa.pub 中的内容复制并配置到 GITLAB

idea配置ssh隧道mysql idea配置ssh隧道_文件路径_08


③ 测试是否配置成功,本地打开 Git Bash ,然后输入以下命令测试

ssh -T git@公司GIT地址

idea配置ssh隧道mysql idea配置ssh隧道_git_09

IDEA 配置 SSH 登陆

① 打开 IDEA ,指定 id_rsa 的路径

idea配置ssh隧道mysql idea配置ssh隧道_git_10


② 配置完成后,Clone 项目

idea配置ssh隧道mysql idea配置ssh隧道_用户名_11