生成密钥对

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_rsa
ssh-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_rsa
Host b
HostName 192.158.5.202
User root
Port 1234
IdentityFile ~/.ssh/b_id_rsa # 下面两条命令就可以连上a,b两台机器
ssh a
ssh b

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

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

访问多个github账号

  • 设置不同Host对应同一个HostName但密钥不同
  • 取消全局用户名/邮箱设置,为每个仓库独立设置用户名/邮箱
# 在~/.ssh/config配置文件中添加如下配置
Host account1.github.com
HostName github.com
IdentityFile ~/.ssh/a_id_rsa
Host 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.email
git 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

参考

最新文章

  1. 维翔主机asp主机使用遇到的问题及解决方案总结
  2. gd-jpeg: JPEG library reports unrecoverable error 解决办法
  3. 使用memcache(thinkphp框架学习)
  4. GIS数据格式:Shapefile
  5. java集合类之TreeMap
  6. reason: 'Could not instantiate class named MKMapView'
  7. IIS服务器 远程发布(Web Deploy)配置 VS2010 开发环境 Windows Server 2008服务器系统
  8. assert的基本用法
  9. 【转】php缓冲 output_buffering和ob_start
  10. 从壹开始前后端分离 [ Vue2.0+.NET Core2.1] 十五 ║Vue基础:JS面向对象&字面量& this字
  11. 【转载】阻塞队列之三:SynchronousQueue同步队列 阻塞算法的3种实现
  12. jsoup 解析html
  13. select()函数 的学习
  14. 算法提高 11-1实现strcmp函数
  15. 【BZOJ】3139: [Hnoi2013]比赛
  16. SpringBoot初探
  17. PLSQL Developer是什么?
  18. “No module named bs4”问题
  19. [Algorithm] Inorder Successor in a binary search tree
  20. 【20181103T1】地球发动机【dp优化】

热门文章

  1. (stm32f103学习总结)—stm32 PMW输出实验
  2. Linux下的cman中文帮助手册配置
  3. Altium design使用日常故障总结
  4. Python 图_系列之基于邻接炬阵实现广度、深度优先路径搜索算法
  5. java中如果我老是少捕获什么异常,如何处理?
  6. tcp和udp的头部信息
  7. Struts2-从值栈获取list集合数据(三种方式)
  8. [翻译] 使用 TensorFlow 进行分布式训练
  9. JavaWeb学习day1-web入门&服务器安装
  10. 2021.12.02 P4001 [ICPC-Beijing 2006]狼抓兔子(最小割)