Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Contributor: CovertBotNews - Easy SSH Automation
Easy SSH Automation

<div data-history-node-id="1339961" class="layout layout--onecol">
<div class="layout__region layout__region--content">

<div class="field field--name-field-node-image field--type-image field--label-hidden field--item"> <img src="" width="800" height="600" alt="""" typeof="foaf:Image" class="img-responsive" /></div>

<div class="field field--name-node-author field--type-ds field--label-hidden field--item">by <a title="View user profile." href="" lang="" about="" typeof="schemaTongueerson" property="schema:name" datatype="" xml:lang="">Adam McPartlan</a></div>

<div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>
A script a day will allow you some freedom to play and build other useful
and more complicated scripts. Every day, I attempt to make my life
this I mean, trying to stop doing the repetitive tasks. If a process is repeatable; it
can be scripted and automated. The idea to automate everything is not new, but
try automating a command on a remote host.

SSH is very flexible, and it comes with many options. My absolute favorite is
its ability to let you run a command on a remote server by passing the
flag. An example:

ssh -t 'cat /etc/hosts'

This will <code>ssh</code> to, then run <code>cat
/etc/hosts</code> in your shell
and return the output.

For efficiency, you could create an ssh-key pair.
It's a simple process of creating a passwordless public and a private
keypair. To set this up, use <code>ssh-keygen</code>, and accept the defaults ensuring you
leave the password blank:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/adam/.ssh/id_rsa): y
Enter passphrase (empty for no passphrase): LEAVE BLANK
Enter same passphrase again:
Your identification has been saved in /home/nynet/.ssh/id_rsa.
Your public key has been saved in /home/nynet/.ssh/
The key fingerprint is:
The key's randomart image is:
+---[RSA 2048]----+
|B*++*Bo.=o |
|.+. |
|=*= |

Once completed, copy the public key to the target server. To do this, use

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
/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's password: ********
Number of key(s) added: 1

You will be asked for the password of the target server.

If you have set this up correctly, you won't be asked for your password
next time you <code>ssh</code> to your target.

Execute the original example. It should be quicker now that you don't need to
enter your password.

If you have a handful of servers and want to report
the running kernel versions, you can run <code>uname -r</code> from the command line, but
to do this on multiple devices, you'll need a script.

Start with a file
with a list of your servers, called server.txt, and then run your script to
iterate over each server and return the required information:


<div class="field field--name-node-link field--type-ds field--label-hidden field--item"> <a href="" hreflang="en">Go to Full Article</a>


Forum Jump:

Users browsing this thread: 1 Guest(s)