检查本机是否存在密钥
打开Git Bash
ls -al ~/.ssh
看看是否存在类似id_rsa.pub
的密钥文件。如有,可直接使用该密钥,否则,生成一个新的密钥
生成一个新的密钥
打开Git Bash
ssh-keygen -t ed25519 -C "your_email@example.com"
默认配置在~/.ssh
目录下生成了私钥id_ed25519
文件和公钥id_ed25519.pub
文件
指定密钥名称
ssh-keygen -t ed25519 -C "your_email@example.com" -f name
添加私钥到ssh-agent
启动ssh-agent
eval "$(ssh-agent -s)"
添加私钥
ssh-add ~/.ssh/id_ed25519
添加公钥到GitHub或GitLab
复制公钥文件内容到剪切板
clip < ~/.ssh/id_ed25519.pub
找到GitHub或GitLab的SSH Keys设置界面,添加一个SSH key,将公钥文件内容复制进去
自定义密钥名称或SSH端口配置
打开~/.ssh/config
文件,如果没有则新建
Host gitlab.oc.com
Port 2222
IdentityFile ~/.ssh/id_ed25519_gitlab
验证是否可以通过SSH连接
ssh -T git@your.domain.com
添加私钥到Fork
菜单File -> Configure SSH Keys 勾选对应的私钥即可
将URL改为SSH连接
git remote set-url origin git@your.domain.com:xxx/xxx.git
PREVIOUSIDEA基于Eclipse keymap的常用快捷键
NEXTJUnit5使用