1

Short version

How can I pipe text from a local machine/server and append it (not overwrite) to a file in a remote machine/server?


Long version

I wished to append my ~/.ssh/rsa_pub (public key) from local to a remote ~/.ssh/authorized_keys.

So I tried this (and hoped for the best):

scp ~/.ssh/id_rsa.pub user@local:user@remote/.ssh/authorized_keys

So I accidently overwrote the remote authorized_keys instead of appending to it... Since my accident, I need to append all those authorized_keys that I lost, one by one, using copy-paste.

Is there a way I can append to the remote's authorized_keys, rather than overwriting it?

Perhaps there is a tool made specifically for things like authorized_keys, but I am also (and more) interested in a general solution along the lines of:

cat local_machine_file.txt >> remote_machine_file.txt

Where I only care about appending to the end of the file, and not at a specific line of a file.


What I tried

Well I read the whole of man scp, several ssh key generating tutorials, and this. The latter is actually what inspired me to unintendedly overwrite remote's authorized_keys... After reading all these ssh key generating tutorials I am generally frustrating at how much they all seem to focus on "generating private/public keys from scratch", assuming the remote and local machines do not already have .ssh/* stuff already in them. I also spent several hours in total searching among: SO, SuperUser and here.

  • 2
    The `ssh-copy-id` utility solves this problem. – Michael Hampton Feb 13 '17 at 23:08
  • 1
    That's covered as well. – Michael Hampton Feb 13 '17 at 23:10
  • For all who want to learn either: (i) how to append local ssh public key to remote /.ssh/authorized_keys, and/or (ii) how to append local data to remote file, go here: http://serverfault.com/questions/170992/looking-for-a-one-step-solution-to-appending-my-ssh-public-key-to-a-servers-aut @MichaelHampton, thanks mate, I learnt a lot. – hello_there_andy Feb 14 '17 at 11:31

0 Answers0