SSH多秘钥管理

一.生成新SSH密钥

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

复制代码
ssh-keygen -t rsa -b 4096 -C "[email protected]" #文件改为id_rsa1,id_rsa1.pub
ssh-keygen -t rsa -b 4096 -C "[email protected]" #文件改为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 [email protected] #测试服务器登录
git clone [email protected]: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
相关推荐
Leo.yuan10 分钟前
数据湖是什么?数据湖和数据仓库的区别是什么?
大数据·运维·数据仓库·人工智能·信息可视化
程序员JerrySUN31 分钟前
Linux 内核内存管理子系统全面解析与体系构建
java·linux·运维
CIb0la41 分钟前
Ai自动补全编程工具:llama vscode
运维·开发语言·学习·测试工具·程序人生
rui锐rui1 小时前
大模型模型部署和暴露接口
linux·运维·服务器
BJ_Bonree1 小时前
博睿数据×华为, 共筑智慧金融新未来
运维
孙克旭_1 小时前
day030-Shell自动化编程-函数
linux·运维·自动化
IT葛大侠1 小时前
OSPF域内路由
运维·网络·计算机网络
面朝大海,春不暖,花不开3 小时前
管理数据洪流:自动化处理与归档每日数据文件的策略与实践
运维·python·自动化
码农101号11 小时前
Linux中shell编程表达式和数组讲解
linux·运维·服务器
powerfulzyh11 小时前
非Root用户启动SSH服务经验小结
运维·ssh