Steps to install pssh on CentOS7:
Here are the simple steps for the installation of pssh on CentOS7:
Here are the simple steps for the installation of pssh on CentOS7:
pssh is a program for executing ssh in parallel on a number of hosts. It provides features such as sending input to all of the processes, passing a password to ssh, saving output to files, and timing out.
Install epel:
# yum install epel-release
Install pssh:
# yum install pssh
create pssh_hosts.txt file and enter the hosts need to target:
# cat pssh_hosts.txt
# write hosts per line like follows
#user@target_ip
root@192.168.100.100
we should do key-pair between the master host and targets, this is the only way to get things done.(simply login the target from master node for Host key verification)
# ssh root@192.168.100.100
Test with single commands
# pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentications=password -i "hostname"
# pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentications=password -i "uptime"
Output:
[root@master pssh]# pssh -h ./pssh_hosts.txt -A -O PreferredAuthentications=password -i "uptime"
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 16:27:59 [SUCCESS] root@192.168.100.100
21:27:57 up 1 day, 1:30, 1 user, load average: 0.00, 0.01, 0.05
To executes scripts on the target machines:
To executes scripts on the target machines:
# cat pssh/tst.sh
#!/bin/bash
touch /root/CX && echo "File created"
# pssh -h ./pssh_hosts.txt -A -O PreferredAuthentications=password -I<./tst.sh
make it simple:
# pssh -H '192.168.100.101' -l 'root' -A -O PreferredAuthentications=password -I< ./tst.sh
Output:
[root@master pssh]# pssh -H '192.168.100.101' -l 'root' -A -O PreferredAuthentications=password -I< ./tst.sh
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password:
[1] 16:24:30 [SUCCESS] 192.168.100.101
To execute commands without password prompting, we need to create key-pair between the servers.
To execute commands without password prompting, we need to create key-pair between the servers.
Creating key pair:
We are trying to attempt login serverB from serverA
Create SSH-Kegen Keys on serverA:
# ssh-keygen -t rsa
Copy the 'id_rsa.pub' file from serverA to master serverB:
# ssh-copy-id root@<serverB-ip>
Now try logging into the machine, with: "ssh 'root@serverB-IP'"
and check to make sure that only the key(s) you wanted were added.
(or)
# cat .ssh/id_rsa.pub | ssh root@<serverB-ip> 'cat >> .ssh/authorized_keys'
Now try to login the serverB from serverA:
# ssh root@serverB-IP
Output:
Last login: d.a.t.e a.n.d t.i.m.e from serverA-ip
Okay, Lets try the commands without password:
Through pssh_hosts.txt file:
# pssh -h '/path/to/pssh_hosts.txt' -i 'hostname'
[1] 13:27:56 [SUCCESS] root@192.168.100.100
Master
For single host:
# pssh -H '192.168.100.101' -i 'hostname'
[1] 13:31:16 [SUCCESS] 192.168.100.101
master
Well, executing script this time,
Through pssh_hosts.txt file:
# pssh -h '/root/pssh/pssh_hosts.txt' -I<./tst.sh
[1] 13:32:23 [SUCCESS] root@192.168.100.100
For single host:
# pssh -H '192.168.100.101' -I<./tst.sh
[1] 13:33:42 [SUCCESS] 192.168.100.101
Thanks.
Comments
Post a Comment