Auto ssh over a set of machines

2009/03/19

I just found out that every pc in the lab have sshd running and waiting at port 22.
Now I immediately thought some nice and nasty things like:

  • running the same process everywhere
  • do some funny jokes to the users connected
  • etc etc

    Or simply get a shell with all the laboratory software you need automatically.

    If you also have on those machines a listening xorg then you could also use X11 programs over the ssh, which works like a charm. (ssh -Yc “hostname” “command” for example)

    The only two “problems” are:

  • the need to insert the password every time
  • the need to accept the fingerprint for each new pc
  • Let’s see how to solve them.

    First we generate a new key:

    ssh-keygen -t dsa -f $HOME/.ssh/unilab

    Then we upload the public key to one of the pc’s, as long as the home directory is mounted over the network (of course) it doesn’t matter which one.

     scp $HOME/.ssh/unilab.pub utente@host:.ssh/ 

    Last thing you need to add to the authorized keys your public key (on whatever lab pc you’re logged in).

     cat $HOME/.ssh/unilab.pub >> $HOME/.ssh/authorized_keys 

    Now we can set a really nice configuration in our $HOME/.ssh/config.

    Here it is:

    Host a10?pc*
      User <youruser>
      IdentityFile <your private key>
      Port 22
      StrictHostKeyChecking no
    

    And that’s it, if for example you now do

     ssh a105pc08 

    ssh will find the matching on the regular expression and use those settings, letting you login automatically.

    But we’re not over, how do we know where sshd is up and running?

    Read the rest of this entry »


    Follow

    Get every new post delivered to your Inbox.