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.