git 配置 多git地址 多用户 公钥认证登录配置
配置流程
生成 密钥对
公钥传到 git 服务器(gitlab,github等)
本地配置 ~/.ssh/config 生效
生成密钥对
以 linux 为例(或者 win 下 git 终端)
ssh-keygen -t ed25519 -C "your_email@example.com" -f name1
-t :推荐使用 ed25519 算法
-C :备注,信息
-f :生成的 文件名(包含路径)。 上面 name1 为 当前目录生成
更多: MAC/WINDOWS/LINUX 生成 ssh key
本地 ~/.ssh/config 配置
这里以多网站为例:
# 配置github.com Host https://github.com/ HostName https://github.com/ IdentityFile C:/Users/zengsm/.ssh/id_rsa PreferredAuthentications publickey User username1 # 配置git.gitlab.com Host http://gitlab.zsm.com/ HostName http://gitlab.zsm.com/ IdentityFile C:/Users/zengsm/.ssh/id_rsa_gitlab PreferredAuthentications publickey User username2
Host:仓库网站的别名,随意取
HostName:仓库网站的域名(PS:IP 地址应该也可以)
Port: 端口
User:仓库网站上的用户名
IdentityFile:私钥的绝对路径
PreferredAuthentications:配置登录时用什么权限认证--可设为 publickey, password publickey , keyboard-interactive 等
0顶
0 踩
共 0 条评论