首页 技术 正文
技术 2022年11月16日
0 收藏 679 点赞 4,304 浏览 1772 个字

 主要是两个步骤

1.控制主机创建密钥对(私钥和公钥)

2.把密钥对的公钥加入对方的认证列表中

[root@vps ~]# ssh-keygen[root@vps ~]# ssh-copy-id user@192.168.9.111

ssh-keygen -t dsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.9.111

如果不是使用ssh-copy-id 命令把本机的公钥id_rsa.pub添加了远程主机认证列表 authorized_keys中

可以使用免确认机器指纹参数免除第一次的yes确认直接登入,免除了“yes”确认

 ssh -o StrictHostKeyChecking=no user@192.168.9.111
[root@vps ~]# 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:4iGGv/oqZhBk2wYs1+VIQBzeYNOh7zsfCUPa1N7d0EY root@vps
The key's randomart image is:
+---[RSA 2048]----+
|.oB=oo. E |
|.Bo*o+ o |
|+.* = o . o |
|.. X . . . + |
| .+ B + S . . |
|. + = + |
|. o + |
|.o .o . |
|o.o++o. |
+----[SHA256]-----+
[root@vps ~]#
[root@vps ~]# ssh-copy-id user@192.168.9.111
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.9.243 (192.168.9.243)' can't be established.
ECDSA key fingerprint is SHA256:eIe1dqiRPK325D/NXRvXDDNllNGNGXlreNh/o8jNXAY.
ECDSA key fingerprint is MD5:6c:c9:4f:da:6d:fd:3f:3c:8e:a8:69:f5:59:67:16:15.
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
user@192.168.9.243's password:Number of key(s) added: 1Now try logging into the machine, with: "ssh 'user@192.168.9.243'"
and check to make sure that only the key(s) you wanted were added.[root@vps ~]#

免交互批量分发公钥脚本:

#!/bin/bash
rm -rf /root/.ssh/id*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -N ""
for ip in `cat ip`;
do sshpass -p passwd ssh-copy-id -i /root/.ssh/id_rsa.pub "-o StrictHostKeyChecking=no $ip"
done
 
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844