博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SSH管理多密钥
阅读量:7144 次
发布时间:2019-06-28

本文共 1918 字,大约阅读时间需要 6 分钟。

  hot3.png

生成密钥对

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"# 默认情况下在~/.ssh目录下生成id_rsa和id_rsa.pub两个文件# id_rsa是密钥,id_rsa.pub是公钥# 生成a密钥对和b密钥对,-f参数设置密钥文件的文件名ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/a_id_rsassh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/b_id_rsa

连接a机器用密钥a,连接b机器用密钥b

# 在~/.ssh目录下编辑config文件Host a	HostName 192.158.5.201	User root	Port 1234	IdentityFile ~/.ssh/a_id_rsaHost b	HostName 192.158.5.202	User root	Port 1234	IdentityFile ~/.ssh/b_id_rsa	# 下面两条命令就可以连上a,b两台机器ssh assh b

访问github用密钥a,访问gitee用密钥b

# 在~/.ssh/config配置文件中添加如下配置Host github.com	IdentityFile ~/.ssh/a_id_rsaHost gitee.com	IdentityFile ~/.ssh/b_id_rsa# 验证, 如果失败可用-vT参数查看失败原因git -T git@github.comgit -T git@gitee.com

访问多个github账号

  • 设置不同Host对应同一个HostName但密钥不同
  • 取消全局用户名/邮箱设置,为每个仓库独立设置用户名/邮箱
# 在~/.ssh/config配置文件中添加如下配置Host account1.github.com	HostName github.com	IdentityFile ~/.ssh/a_id_rsaHost account2.github.com	HostName github.com	IdentityFile ~/.ssh/b_id_rsa

设置邮箱和用户名

# 设置全局的git config --global user.email "your_email@example.com"git config --global user.name "your_name"# 取消全局的git config --global --unset user.emailgit config --global --unset user.name# 为每个库设置单独的git config user.email "your_email@example.com"git config user.name "your_name"

scp的简化

# 未配置ssh-config之前scp -P 1234 root@xxx.xxx.xxx.xxx:/abc/def .# 配置ssh-config之后scp a:/abc/def .

ssh-agent

ssh-agent bash命令解释: ssh-agent是专为既令人愉快又安全的处理RSA和DSA密钥而设计的特殊程序,不同于ssh,ssh-agent是个长时间持续运行的守护进程(daemon),设计它的唯一目的就是对解密的专用密钥进行高速缓存。ssh包含的内建支持允许它同ssh-agent通信,允许ssh不必每次新连接时都提示您要密码才能获取解密的专用密钥。对于ssh-agent,您只要使用ssh-add把专用密钥添加到ssh-agent的高速缓存中。这是个一次性过程;用过ssh-add之后,ssh将从ssh-agent获取您的专用密钥,而不会提示要密码短语来烦您了。 如果出现如下提示信息说明没有SSH Key在代理中

补:遇到的一个错误,提示信息如下

/root/.ssh/config: line 5: Bad configuration option: identifyfile/root/.ssh/config: terminating, 1 bad configuration options# 原因是拼写错误# IdentifyFile  -->   IdentityFile

参考

转载于:https://my.oschina.net/yysue/blog/1815742

你可能感兴趣的文章
Nginx整合PHP原理
查看>>
备份数据表、还原数据表
查看>>
【LeetCode】29. Divide Two Integers
查看>>
一致性 Hash 算法的实际应用
查看>>
Java015-网络编程
查看>>
iOS开发-安全释放
查看>>
裁员浪潮之下,互联网人该何去何从?
查看>>
[译] PEP 255--简单的生成器
查看>>
ZABBIX 企业级分布式监控系统 1 监控系统简介
查看>>
小程序 — 实现左滑删除效果②
查看>>
教你如何反编译app,拿到加密方式
查看>>
python调用HanLP
查看>>
zookeeper实现分布式锁
查看>>
一个简单的js队列,逻辑很清晰
查看>>
【52ABP实战教程】0.2-- VSTS中的账号迁移到东亚
查看>>
润乾报表数据导出时的等待提示
查看>>
ASP.Net Core 运行错误 Http Error 502.5 解决办法
查看>>
崩溃bug日志总结2
查看>>
京东IoT没有“野心”
查看>>
Linux wired unmanageed
查看>>