Linux 中常用的免密连接。通过秘钥对实现。当不指定密钥文件时,使用的是默认的id_rsa

  • 创建秘钥对命令

ssh-keygen

-t : 指定秘钥类型。默认是rsa. 可以省略-C : 设置注释文字-f : 指定秘钥文件存储的文件名。 默认是id_rsa

实例:

# ssh-keygen

# 指定文件名# ssh-keygen -f /root/.ssh/gitlab -C "GITLAB"

  • /root/.ssh/config 配置

# 多个密钥对时。ssh连接时,需要指定使用的私钥文件. 当不指定时,使用的时默认的id_rsa文件。所以当你复制的公钥不是id_rsa.pub时,ssh连接也会需要输入密码,实现不了免密登录# 指定密钥文件另一种方法是在linux 主机的 /root/.ssh 创建config文件。在config文件定义,在使用ssh连接时,会进行区分。# touch /root/.ssh/config# cat /root/.ssh/configHost 192.168.1.194  Hostname 192.168.1.194  #PreferredAuthentications publickey  IdentityFile /root/.ssh/nginx01Host 192.168.1.191  Hostname 192.168.1.191  #PreferredAuthentications publickey  IdentityFile /root/.ssh/nginx02  Host 192.168.1.190  Hostname 192.168.1.190  #PreferredAuthentications publickey  # User root  IdentityFile /root/.ssh/gitlab
  • congfig 配置gitee 和  github

# giteeHost gitee.comHostName gitee.comPreferredAuthentications publickeyIdentityFile ~/.ssh/gitee_rsa# githubHost github.comHostName github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/github_rsa

使用ssh 命令时指定秘钥文件。

# ssh -i /root/.ssh/nginx01  192.168.1.194

ssh-copy-id 命令:

-i : 复制指定的公钥到远程主机。默认复制的文件是 /root/.ssh/id_rsa.pub# ssh-copy-id  -i /root/.ssh/nginx02.pub 192.168.1.190


©著作权归作者所有:来自51CTO博客作者18616373425的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. Java Web: 发送请求,CSS文件 和 JS文件引用失败
  2. 附实战代码|告别OS模块,体验Python文件操作新姿势!
  3. 让Python在后台自动解压各种压缩文件!
  4. 10行Python代码自动清理电脑内重复文件,解放双手!
  5. 用Python打造一款文件搜索工具,所有功能自己定义!
  6. Python办公自动化|自动整理文件,一键完成!
  7. 从零到一学懂区块链(4):密钥
  8. Python地信专题 | 基于geopandas的空间数据分析-文件IO篇
  9. n种方式教你用python读写excel等数据文件

随机推荐

  1. Android Spinner (Drop Down List) Examp
  2. Android 设备管理
  3. Android ADT Bundle 0917,SDK Tools r22.2
  4. Android Activity getCurrentFocus()
  5. android Notification 工具类
  6. Android=》Nitification
  7. android 用代码画圆
  8. Android JNI开发
  9. android AOP编程
  10. android studio 关闭log 打印