Open Source For You — December 2017

(Steven Felgate) #1
Next, test with single commands:

pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentication


s=password -i “hostname”


pssh -h /path/to/pssh_hosts.txt -A -O PreferredAuthentication


s=password -i “uptime”


The output is:

[root@master pssh]# pssh -h ./pssh_hosts.txt -A -O PreferredAut
hentications=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] [email protected]
21:27:57 up 1 day, 1:30, 1 user, load average: 0.00, 0.01,
0.05


To execute scripts on the target machines, type:

cat pssh/tst.sh


#!/bin/bash
touch /root/CX && echo “File created”


pssh -h ./pssh_hosts.txt -A -O PreferredAuthentications=passw


ord -I<./tst.sh


Now let us make it simple:

pssh -H ‘192.168.100.101’ -l ‘root’ -A -O PreferredAuthentica


tions=password -I< ./tst.sh


The output is:

[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 a key-pair between the servers. Let us look at
how to do that.
We are trying to attempt to log in to serverB from
serverA.
Create SSH-Kegen keys on serverA, as follows:


ssh-keygen -t rsa


Copy the id_rsa.pub file from serverA to master
serverB:


ssh-copy-id root@


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.
Now, try to use pssh without the password on the
command line.
—Ranjithkumar T., [email protected]

Find out what an unknown command does,
by using whatis
If you are new to the Linux terminal, then you will probably
wonder what each command does. You are most likely to do a
Google search for each command you come across.
To avoid doing that, use the whatis command, followed
by the command you don’t know. You will get a short
description of the command.
Here is an example:

$ whatis ls
ls (1) -list directory contents

Now you’ll know what the command does, and won’t
have to open your browser and search.

—Siddharth Dushantha, [email protected]

Know how many times a user has logged in
One way to find out the number of times users have
logged into a multi-user Linux system is to execute the
following command:

$last | grep pts | awk ‘{print $1}’ | sort | uniq -c

The above command provides the list of users who
recently logged into the system. The grep utility is used to
remove the unnecessary information, the result of which is
then sent to awk using the shell pipe. awk, which is used for
processing text based data, extracts only the user names from
the text. This list of extracted names is now sorted by passing
the list of names to the sort command, through a shell pipe.
The sorted list of names is then piped to the uniq command,
which filters adjacent matching lines, and the matching lines are
merged to the first occurrence. The -c option of the uniq command,
which displays the number of times a line is repeated, gives you
the number of logins of each user along with the user’s name.
—Sathyanarayanan S., [email protected]

Share Your Open Source Recipes!
The joy of using open source software is in finding ways to get
around problems—take them head on, defeat them! We invite
you to share your tips and tricks with us for publication in
OSFY so that they can reach a wider audience. Your tips could
be related to administration, programming, troubleshooting or
general tweaking. Submit them at http://www.opensourceforu.com.
The sender of each published tip will get a T-shirt.

http://www.OpenSourceForU.com | OPEN SOURCE FOR YOU | DECEMBER 2017 | 105
Free download pdf