[plug] local file referencing in remote ssh commands

Ryan ryan at is.as.geeky.as
Fri Apr 4 10:48:33 WST 2003


I was just about to post a question, then while I was explaining it to
myself I thought to try something else and I answered my own question
... but now still have the same question :)

I was wanting to reference local files in remote ssh commands, but
realised that when using the backtick notation, those bits get run first
(and hence locally) so they do what I want.

I'll paste what I was going to send anyway - it might help someone :)

As I was typing the sentence about the local SSH call getting run first
I figured out what was going on - and therefore the answer to my query
is:

ssh {REMOTE_HOST} "echo `cat ~/.ssh/id_dsa.pub` >>
~/.ssh/authorized_keys"

(`cat ~/.ssh/id_dsa.pub` gets run locally first and thus picks up the
contents of the local file)

Having discovered that - is there a more correct or established way to
reference local files in remote calls than this?

Thanks,

Ryan


Here is the original email before someone switched on the light:
======================================================================
I'm curious if there is any neat way to reference local files in remote
ssh commands.

I think the best example would be deploying ssh keys to a remote server:

Let's say we have made the keys and want to copy it into the
~/.ssh/authorized_keys file on the remote server.

Normally, rather than farting around with several commands and/or
logging into the remote host to perform some of them, I do this:

ssh {REMOTE_HOST} "echo `ssh {LOCAL_HOST} cat ~/.ssh/id_dsa.pub` >>
~/.ssh/authorized_keys"

Chuck in the two passwords and it is done. In that command, the local
SSH call gets run first and thus does not get run from the remote host
as it looks like it might .. but it all still works.

Is there a way to do this with one ssh command so you can 'reference'
the local file and have it automagically and transparently sent across
as needed?

Something like this:

ssh {REMOTE_HOST} "cat {magical-neat-reference-to-local-file} >>
~/.ssh/authorized_keys"
=======================================================================




More information about the plug mailing list