centos6.5配置ssh免秘钥登陆执行pssh命令的讲解

SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。

pssh是python写的可以并发在多台机器上批量执行命令的工具,它的用法可以媲美ansible的一些简单用法,执行起来速度比ansible快它支持文件并行复制,远程命令执行,杀掉远程主机上的进程等等。杀手锏是文件并行复制,,当进行再远程主机批量上传下载的时候,最好使用它。

1.检查并安装pssh,yum list pssh

2.因为没有配置免秘钥登陆,pssh命令执行失败。

[root@bogon ]# pssh -H root@192.168.245.129 -i uptime
[1] 11:00:36 [FAILURE] root@192.168.245.129 Exited with error code 255
Stderr: The authenticity of host '192.168.245.129 (192.168.245.129)' can't be established.
RSA key fingerprint is 84:2d:70:33:1c:45:fa:e6:4b:94:72:7e:10:98:7c:a8.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.

3.生成秘钥。

[root@bogon tmp]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
9e:14:9a:cc:8d:9b:fd:51:c5:68:24:e1:ce:c6:d7:33 root@bogon
The key's randomart image is:
+--[ RSA 2048]----+
| o.. |
| . o o |
| . . o o |
| o = = . o |
| * S = o E |
| * o o o |
| o + . |
| . . |
| . |
+-----------------+
[root@bogon .ssh]# ll
total 8
-rw------- 1 root root 1675 Aug 22 11:06 id_rsa
-rw-r--r-- 1 root root 392 Aug 22 11:06 id_rsa.pub

4.拷贝到被管对象。

[root@bogon .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.245.129
The authenticity of host '192.168.245.129 (192.168.245.129)' can't be established.
RSA key fingerprint is 84:2d:70:33:1c:45:fa:e6:4b:94:72:7e:10:98:7c:a8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.245.129' (RSA) to the list of known hosts.
reverse mapping checking getaddrinfo for bogon [192.168.245.129] failed - POSSIBLE BREAK-IN ATTEMPT!
root@192.168.245.129's password:
Now try logging into the machine, with "ssh 'root@192.168.245.129'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.

5.pssh命令执行成功。

[root@bogon .ssh]# pssh -H root@192.168.245.129 -i uptime
[1] 11:10:39 [SUCCESS] root@192.168.245.129
20:10:39 up 2:07, 1 user, load average: 0.00, 0.00, 0.00
赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-62778877-8306;邮箱:fanjiao@west.cn。本站原创内容未经允许不得转载,或转载时需注明出处:西部数码知识库 » centos6.5配置ssh免秘钥登陆执行pssh命令的讲解

登录

找回密码

注册