Linux pssh安装与使用

说明:我这是没有在密钥认证的情况下操作

1、安装pssh

[root@libin ansible]# yum install -y pssh

[root@libin ansible]# rpm -ql pssh
/usr/bin/pnuke
/usr/bin/prsync
/usr/bin/pscp
/usr/bin/pslurp
/usr/bin/pssh
/usr/bin/pssh-askpass

2、使用pssh

[root@libin ansible]# man pssh

[root@libin ansible]# cat hosts.txt
192.168.124.134
192.168.124.132

[root@libin ansible]# pssh -h hosts.txt hostname
[1] 19:13:21 [SUCCESS] 192.168.124.132
[2] 19:13:21 [SUCCESS] 192.168.124.134

[root@libin ansible]# pssh -h hosts.txt “hostname > /tmp/libin.txt” #追加到 /tmp/libin.txt
[1] 19:16:32 [SUCCESS] 192.168.124.132
[2] 19:16:32 [SUCCESS] 192.168.124.134

[root@libin ansible]# cat /tmp/libin.txt
libin.com

-i:执行命令时,将标准错误的和标准输出的信息都显示出来

-p:同一时间并发去执行命令,指定最大的并发数量

-A:输入用户的密码

[1] 19:38:32 [SUCCESS] 192.168.124.134
wlcome to study redhat-linux
libin3.com
[2] 19:38:32 [SUCCESS] 192.168.124.132
libin.com

[root@libin ansible]# pssh -A -ih hosts.txt ls -l /tmp/

3、使用pscp

[root@libin ansible]# pscp -h hosts.txt /etc/hosts /tmp/ #将客户端的/etc/hosts拷贝到/tmp/下
[1] 19:43:36 [FAILURE] 192.168.124.134 Exited with error code 1
[2] 19:43:36 [SUCCESS] 192.168.124.132

[root@libin ansible]# pssh -h hosts.txt ls -l /tmp/
[1] 19:45:19 [SUCCESS] 192.168.124.132
[2] 19:45:19 [SUCCESS] 192.168.124.134

[root@libin ansible]# pssh -ih hosts.txt ls -l /tmp/ #查看/tmp/目录下的所有文件

=========================================

(1)把公钥发到服务器

在一台机器上可用管理和控制其他机器

secureCRT /xshell/ssh秘钥认证/pssh

1、创建公钥

[root@libin ansible]# ssh-keygen #(默认为RSA类型,已经比较过时)

[root@libin ansible]# ssh-keygen -t dsa #-t:指定类型
Generating public/private dsa key pair. #生成一对公钥,私钥
Enter file in which to save the key (/root/.ssh/id_dsa): 私钥位置 #默认存放的目录为/root/.ssh/id_dsa,ll -a 查看所有隐藏的文件

Enter passphrase (empty for no passphrase): 设置密码

Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:
SHA256:yQiMcqnRlhBguTI5uApgP8hv+z2upk6/eXmbHZSNFvI root@libin.com
The key’s randomart image is:
+—[DSA 1024]—-+
|=o. |
|.+ = |
|+.O o . . |
|BO . o .o = |
|+o . S E . |
|oo o o |
|o … . . |
|. .o..o+ .o . |
| o+=
=ooo.. |
+—-[SHA256]—–+

[root@libin ansible]# ll /root/.ssh/
总用量 24
-r——–. 1 root root 1584 2月 22 2022 authorized_keys
-rw——- 1 root root 668 9月 25 20:10 id_dsa
-rw-r–r– 1 root root 604 9月 25 20:10 id_dsa.pub

2、发送公钥到各个服务器

[root@libin ansible]# ssh-copy-id -i /root/.ssh/id_dsa.pub root@172.168.124.134 #-i:指定公钥位置 ,-f :指定私钥位置

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_dsa.pub”
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

[root@libin ansible]# ssh 192.168.124.134 hostname #连接服务器执行一个命令,检查
Warning: Permanently added ‘192.168.124.134’ (ECDSA) to the list of known hosts.

wlcome to study redhat-linux
libin3.com

3、sshpass(专门用来给ssh相关的命令提供密码)

[root@libin ansible]# sshpass -p123456 ssh root@192.168.124.134 hostname #-p:指定一个密码
Warning: Permanently added ‘192.168.124.134’ (ECDSA) to the list of known hosts.

wlcome to study redhat-linux
libin3.com

[root@libin ansible]# rm -fr /root/.ssh/id_rsa* #清除密钥对

[root@libin ansible]# ssh-keygen -t dsa -f /root/.ssh/id_dsa -P “” #-t:指定密钥类型, -f:指定私钥 -P:指定密码,这里意思是空密码

[root@libin ansible]# fo i in {132..134};do sshpass -p123456 ssh-copy-id -i /root/.ssh/id_rsa.pub -o StrictHostKeyChecking=no root@192.168.124.$i;done #利用for循环下发私钥

ssh 自动维护并检查一个身份数据库, 它包含所有(成功)来访的主机的身份数据. 主机密钥存放在用户根目录下的 $HOME/.ssh/known_hosts文件中. 另外, SSH 自动检查 /etc/ssh/ssh_known_hosts 里面已知的主机. 任何新主机将被自动添加到用户文件中.如果某个主机的身份发生改变, ssh 就会发出警告, 并且关闭对它的密码认证, 以防止特洛伊木马窃取用户密码.这个机制的另一个目的是防止中间人攻击, 否则这种攻击可能会绕过加密系统.StrictHostKeyChecking
选项用来防止登录到主机密钥不能识别或发生改变的那些机器.

[root@libin ansible]# for i in {1..5} #例子:for循环的用法

do
echo $i www.baidu.com
done
1 www.baidu.com
2 www.baidu.com
3 www.baidu.com
4 www.baidu.com
5 www.baidu.com

================================================================

Original: https://www.cnblogs.com/libin-linux/p/16728650.html
Author: LB_运维技术
Title: Linux pssh安装与使用

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/606712/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 多线程/哈希slot/集群

    io多线程 以前的redis是单线程模型,其实就是多路复用机制,知道多路复用的来一波6,我们在架构师课程中讲过,那么netty也有,看过老师相关课程的也应该知道。这里不多说了。 R…

    Linux 2023年5月28日
    094
  • linux用户组管理

    一、简介 1、每个用户都有一个用户组,系统可以对一个用户组中的所有用户进行集中管理,不同Linux系统对用户组的规定有所不同,如:Linux下在创建用户时,不指定用户组名,则会同时…

    Linux 2023年5月27日
    0113
  • [apue] 标准 I/O 库那些事儿

    标准 IO 库自 1975 年诞生以来,至今接近 50 年了,令人惊讶的是,这期间只对它做了非常小的修改。除了耳熟能详的 printf/scanf,回过头来对它做个全方位的审视,看…

    Linux 2023年6月6日
    0128
  • 【MySQL篇】Navicat导入SQL大文件报错终极解决方案

    面对 大数据库文件(一般50M以上),使用Navicat导入的时候容易出现 [ERR]2006等报错问题,此文提供了几种办法,包括修改MySQL的配置参数在网上也有很多详细教程介绍…

    Linux 2023年6月13日
    095
  • zabbix自定义监控进程与日志

    zabbix自定义监控进程与日志 zabbix自定义监控进程与日志 zabbix自定义监控进程 zabbix自定义监控日志 zabbix自定义监控进程 现在我们需要监控客户端的某一…

    Linux 2023年6月13日
    0115
  • 微服务的性能监控、压测和调优(转载自知乎:阿里自动化测试群)

    一、何为压力测试 性能压测是什么:就是考察当前 软件和 硬件环境下,系统所能承受的 &amp…

    Linux 2023年6月8日
    096
  • 白话电子签章原理及风险

    因为业务需要近来在对接一个线上的电子签章平台, 签完的效果就是在PDF上盖一个红色的章。内部过程沟通中发现,对这个红色章背后的证明逻辑,技术原理,能够了解的比较清楚的人还是很少的。…

    Linux 2023年6月13日
    086
  • MySQL manager or server PID file could not be found!

    [root@centos var]# service mysqld stop MySQL manager or server PID file could not be found…

    Linux 2023年6月13日
    081
  • 最短的可通过编译的C语言程序

    要求:写一个最短的,能通过编译的C语言程序,但不要求能正确运行。 一般人首先想到的是除0。即 除0会引发SIGFPE信号(浮点异常)。 我们也可以删掉return,但是这样做的话编…

    Linux 2023年6月14日
    080
  • 你真的了解JAVA中对象和类、this、super和static关键字吗

    作者:小牛呼噜噜 | https://xiaoniuhululu.com计算机内功、JAVA底层、面试相关资料等更多精彩文章在公众号「小牛呼噜噜 」 Java对象究竟是什么? 创建…

    Linux 2023年6月6日
    0100
  • Linux常用磁盘管理命令详解

    du du命令用于查看文件和目录磁盘的使用空间。 命令语法: du [参数] [文件&amp…

    Linux 2023年5月27日
    0102
  • Linux命令篇-awk 命令

    gawk – pattern scanning and processing language; awk:gawk是Unix中原始awk程序的GNU版本,强大之处在于可…

    Linux 2023年6月13日
    086
  • 【原创】Linux虚拟化KVM-Qemu分析(七)之timer虚拟化

    背景 Read the fucking source code! –By 鲁迅 A picture is worth a thousand words. –…

    Linux 2023年6月8日
    097
  • 位运算(一)

    位运算的一般应用 功能 例子 运算 去掉最后一位 1110101->111010 x>>1 在最后加0 1110101->11101010 x< 通过…

    Linux 2023年6月8日
    0127
  • php微信自定义分享链接,标题,描述,缩略图配置步骤

    微信公众号开发,自定义分享链接,标题,描述,缩略图接口 1、文件目录结构 2、后台代码: wxshare.php 注意:使用此代码,只需要把wxshare.php文件下面的appi…

    Linux 2023年6月7日
    083
  • shell 获取进程号

    Shell最后运行的后台PID(后台运行的最后一个进程的进程ID号) $! Shell本身的PID(即脚本运行的当前进程ID号 $$ Original: https://www.c…

    Linux 2023年5月28日
    083
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球