SSH多秘钥管理

一.生成新SSH密钥

打开 Git Bash,使用以下命令,其中邮箱替换为有效地址。

复制代码
ssh-keygen -t rsa -b 4096 -C "xx@qq.com" #文件改为id_rsa1,id_rsa1.pub
ssh-keygen -t rsa -b 4096 -C "yy@qq.com" #文件改为id_rsa2,id_rsa2.pub

二.服务器端添加公钥

在多个服务器端,分别手动添加SSH对应的pub key内容。

三.客户端启动SSH agent,添加秘钥

复制代码
#1.shell下启动ssh agent
eval "$(ssh-agent -s)"
#2.复制id_rsa1和id_rsa2到 ~/.ssh目录,并执行如下命令
ssh-add ~/.ssh/id_rsa1
ssh-add ~/.ssh/id_rsa2

四.客户端SSH配置管理

复制代码
#1.建立配置文件
touch ~/.ssh/config 

#2.config文件添加如下内容
# server1
Host first.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa1

#server2
Host second.com
    HostName xxxxx.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa2

五.验证登录和下载

复制代码
ssh -T git@github.com #测试服务器登录
git clone git@github.com:git/git.git #使用实际仓库地址,验证代码下载

六.常见问题

常见问题:windows下,git代码下载后,编译报错。

原因:windows自动转换linux文件的回车换行及文件结束符。解决方法:

复制代码
#1.全局仓库配置,只需运行一次
git config --global core.autocrlf false
git config --global core.eol lf
#2.检查配置是否起效:
git config --global core.autocrlf
git config --global core.eol
相关推荐
冰橙子id3 小时前
linux-远程访问管理(sshd,scp,sftp)
linux·网络·ssh
saynaihe6 小时前
ubuntu 22.04 anaconda comfyui安装
linux·运维·服务器·ubuntu
企鹅与蟒蛇6 小时前
Ubuntu-25.04 Wayland桌面环境安装Anaconda3之后无法启动anaconda-navigator问题解决
linux·运维·python·ubuntu·anaconda
小蜜蜂爱编程6 小时前
ubuntu透网方案
运维·服务器·ubuntu
AI视觉网奇6 小时前
git 访问 github
运维·开发语言·docker
头发那是一根不剩了7 小时前
nginx:SSL_CTX_use_PrivateKey failed
运维·服务器
七夜zippoe7 小时前
破解 VMware 迁移难题:跨平台迁移常见问题及自动化解决方案
运维·自动化·vmware
hweiyu008 小时前
docker简介
运维·docker·容器
Sally璐璐9 小时前
OpenVPN:深度解析开源 VPN 解决方案
运维·开源
阿巴~阿巴~9 小时前
理解Linux文件系统:从物理存储到统一接口
linux·运维·服务器