On Fri, 2011-08-12 at 19:57 +1200, Aidan Gauland wrote:
> On 12/08/11 19:51, Mallett wrote: 
> > I have been wondering is there a way that I can copy a rsa public
> > key to a server in one command. 
> > 
> > I can do this 
> > 
> > 
> > ssh 192.168.1.220 mkdir -m 700 ~/.ssh
> > 
> > rsync /home/aaa/.ssh/id_rsa.pub
> > [email protected]:.ssh/authorized_keys
> > 
> > 
> > 
> > but it means I have to log in twice. 
> 
> You could try
> mkdir -m 700 dot.ssh-remote && cp .scp/id_rsa.pub 
> dot.ssh-remote/authorized_keys && scp -r dot.ssh-remote 192.168.1.220:.ssh
> OK, so it's multiple commands, but only one remote login.  I have no
> idea if this is the simplest way to do this.
> 
> --Aidan
Erm...

You want to *append* to authorized_keys if it exists.

key=`cat id_rsa.pub`; ssh user@host 'mkdir .ssh ; chmod 700 .ssh ; echo
$key >> .ssh/authorized_keys'

should be the core of it. Add error handling, etc to taste.

Steve


-- 
Steve Holdoway <[email protected]>
http://www.greengecko.co.nz
MSN: [email protected]
Skype: sholdowa


_______________________________________________
Linux-users mailing list
[email protected]
http://lists.canterbury.ac.nz/mailman/listinfo/linux-users

Reply via email to