[dundee] Pushing SSH Certs

Gavin Carr gavin at openfusion.com.au
Fri Nov 27 11:34:44 UTC 2009


Howdy, I'm a new lurker from NZ via Australia, recently moved to St. Andrews.
Hope to make it to the LUG sometime, given there doesn't seem to be one here
any longer.

On Fri, Nov 27, 2009 at 10:24:09AM +0000, Rick Moynihan wrote:
> It pushes your ssh public key to the specified hosts (for passwordless
> login) and if there isn't an ssh keypair on your box, it'll create
> one.  This is one of those utility functions that I've been meaning to
> write for years....  With the proliferation of servers and VM's I deal
> with this is gonna be mega handy.
> 
> # Push SSH public key to remote servers
> push_ssh_cert() {
>     local _host
>     test -f ~/.ssh/id_rsa.pub || ssh-keygen -t rsa
>     for _host in "$@";
>     do
>         echo $_host
>         ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
>     done
> }

It assumes the ~/.ssh directory exists, which isn't necessarily the case.
It's not in /etc/skel on Ubuntu/RHEL/Fedora, at least, afaik.

So the ssh line should probably be (untested):

  ssh $_host 'mkdir -pm0700 ~/.ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub

Otherwise nice. 


> Anybody got any other handy bash snippets?

A couple of my favourites are:

  lead() {
    ls $LS_OPTIONS -lt | head ${1:--20}
  }

which is a 'head' on a time-ordered ls i.e. shows you the N most recent 
entries in the current directory - useful for looking for things that recently
changed etc. Another is:

  alias l1='ls -t | head -1'

which echoes the most recently changed file. That lets you do things like

  create-some-file.sh
  vi `l1`

to edit the file you just created, etc.

Cheers,
Gavin




More information about the dundee mailing list