配置ssh互信
配置基于密钥认证的免密登录
用到的命令:
ssh-keygen:创建公钥和密钥,会生成id_rsa和id_rsa.pub两个文件
生成ssh密钥后,密钥将默认存储在家目录下的.ssh/目录中。私钥和公钥的权限就分别为600和644。.ssh目录权限必须是700。ssh-copy-id:把本地的公钥复制到远程主机的authorized_keys文件(不会覆盖文件,是追加到文件末尾),并且会设置远程主机用户目录的.ssh和.ssh/authorized_keys权限
权限为:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
1.在客户端生成公钥和私钥
客户端的ip是192.168.32.125,服务端是192.168.32.130
[root@clien ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:SAkbr/cL3EvxhkDVc6Z69uLvgcU+3OX7cBCD2f08W5c root@clien
The key's randomart image is:
+---[RSA 2048]----+
| o .. |
| = o o o+ . |
| . = =o + .|
| + . .. +o|
| . + S. o .E*|
| o +.+o= . +=|
| o =o+.= o.o|
| o +. .o o.|
| o..+o .o|
+----[SHA256]-----+
[root@clien ~]# ls .ssh/
id_rsa id_rsa.pub
ssh-keygen -t [rsa|dsa]
三次回车,第一个是指定路径,后两个是密码,都用默认
生成ssh密钥后,密钥将默认存储在家目录下的.ssh/目录中。私钥和公钥的权限就分别为600和644。.ssh目录权限必须是700。
2.把公钥发送到服务端
通过ssh-copy-id将密钥复制到另一系统时,它默认复制~/.ssh/id_rsa.pub文件
[root@clien ~]# ssh-copy-id root@192.168.32.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.32.130 (192.168.32.130)' can't be established.
ECDSA key fingerprint is SHA256:mxRfnjvv98dVsD4gCq/koRMg7r05Sh43473F7Y7PoMw.
ECDSA key fingerprint is MD5:22:f7:ba:1e:0a:4c:a7:1b:17:98:2d:dd:f0:f5:70:10.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.32.130's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.32.130'"
and check to make sure that only the key(s) you wanted were added.
也可以使用scp等工具,把id_rsa.pub上传另一台服务器~/.ssh/下,然后改名为authorized_keys
例如
[root@clien ~]# scp .ssh/id_rsa.pub root@192.168.32.130:/root/.ssh/authorized_keys
root@192.168.32.130's password:
id_rsa.pub 100% 392 677.6KB/s 00:00
[root@clien ~]# ssh 192.168.32.130
Last login: Sun Apr 26 02:44:59 2020 from 192.168.32.125
[root@server ~]#
//scp命令常用选项
-r //递归复制
-p //保持权限
-P //端口
-q //静默模式
-a //全部复制
3.验证
[root@clien ~]# ssh 192.168.32.130
Last login: Sun Apr 26 01:38:58 2020 from 192.168.32.1
[root@server ~]#
配置ssh互信的更多相关文章
- linux配置ssh互信
公钥认证的基本思想: 对信息的加密和解密采用不同的key,这对key分别称作private key和public key,其中,public key存放在欲登录的服务器上,而private key为特 ...
- 批量配置SSH互信脚本
在大规模自动化部署时我们常常需要配置好服务器的SSH互信,以便自动化脚本可以免密登录远程服务器,常规的手动配置SSH互信步骤如下: 使用ssh-keygen生成本地ssh key(mha01),生成的 ...
- 配置ssh互信的一个小问题记录
在我们安装集群软件时,经常需要配置机器之间的互信,每个人也有一套自己熟悉的方法. 但是在今天配置互信过程中,发现操作过程还是一样,但是就是不能互信,通过查找资料解决了,做一下记录. 我经常使用的方式: ...
- Linux之间配置SSH互信(SSH免密码登录)
为简化SSH过程,采用证书方式,免去SSH登入时需要输入账号密码的过程,具体操作如下: 一.在SSH服务器所在机器上 1.以root用户登录,更改ssh配置文件 /etc/ssh/sshd_confi ...
- Linux快速配置集群ssh互信
之前在<记录一则Linux SSH的互信配置过程>.<Vertica 7.1安装最佳实践(RHEL6.4)>中,都分别提到了配置ssh互信的方法,本文在此基础上进一步整理配置s ...
- 三台机器之间root用户ssh互信配置
三台机器之间root用户ssh互信配置 (1)在所有的主机上执行:ssh-keygen -t rsa # 在每台都需要操作,一路回车 (2)将所有机子上公钥(id_rsa.pub)导到一个主机的/ro ...
- 三台机器之间ssh互信配置
三台机器之间ssh互信配置 环境介绍:192.168.65.128 my1-222192.168.65.129 my2-223192.168.65.130 web224 # 步骤一:# ...
- Ansible批量更新远程主机用户密码 (包括Ansible批量做ssh互信)
按照集团运维信息安全制度, 需要每个一段时间对线上服务器密码进行一次变更,通过shell脚本部署比较繁琐,所以决定采用ansible脚本对远程主机root密码进行批量重置,该脚本已经在稳定运行在正式环 ...
- 快速建立ssh互信(转)
转自:魏巍的Linux酒吧 - 51CTO技术博客(http://weiweilinux.blog.51cto.com/3349074/1048212) 快速建立ssh互信 因为工作中经常需要配置服务 ...
随机推荐
- 小书MybatisPlus第2篇-条件构造器的应用及总结
一.条件构造器Wrapper Mybatis Plus为我们提供了如下的一些条件构造器,我们可以利用它们实现查询条件.删除条件.更新条件的构造. 条件构造器用于给如下的Mapper方法传参,通常情况下 ...
- Linux使用pyinstaller 编译py成可执行程序
0x00 pyinstall 安装 命令行pip install pyinstaller安装 0x01 编译时使用命令pyinstaller -F -w /root/pyfile/图片GPS位置获取 ...
- abp一代数据迁解析
abp版本5.9 概述 数据迁移无非就是两件事情,1.创建数据库,并根据实体创建对应的表:2.添加一些初始数据 abp的数据迁移也是完成这两件事,比较特殊的是它是多租户saas系统,而且支持不同的租户 ...
- LintCode笔记 - 145.大小写转换 - 极简之道 - 最短代码
这道题目一眼就能看出是送分题,当然在这里也不谈高难度的实现逻辑,肯定有同学会想直接用自带函数实现不就可以了吗? 对的,就是这么简单,然而今天的重点是如何把代码简写到最短. 本文章将带你把代码长度从 一 ...
- Python math 、cmath
1.math dir(math) 2.cmath 复数运算
- Python 数字格式转换
# 数字格式转换v1 '''a = input() a1 = list(a) b = ["零", "一", "二", "三&quo ...
- python之class面向对象(进阶篇)
上一篇<Python 面向对象(初级篇)>文章介绍了面向对象基本知识: 面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 类 是一个模板,模板中包装了多个“函数”供使 ...
- day6:双向循环练习&pass_break_continue&for循环
双向循环练习 1.打印10行10列的小星星(两个循环) # j 外循环用来控制行数 j = 0 while j < 10: # i 打印一行十个星星 i = 0 while i < 10: ...
- Go包管理go mod使用
Go Modules介绍 为了解决Go包管理的问题,Go从1.11开始加入了Go Modules这一新特性.让包的依赖和版本管理更加容易. 一个module可以理解为一个单独的包或者模块,module ...
- OSCP Learning Notes - Capstone(3)
DroopyCTF Walkthrough Preparation: Download the DroopyCTF virtual machine from the following website ...