I have some experience using the bash, but this command here which I saw in a tutorial caught me off guard:
cat ~/.ssh/id_rsa.pub | ssh git@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
I know what the command does. It takes the output of the file ~/.ssh/id_rsa.pub
, then ssh
s to a remote server, creates a new directory under user home called .ssh then creates a new file called authorized_keys
and pours the contents of the id_rsa.pub
into that file. What I couldn't figure out is, at which point contents of the id_rsa.pub
file gets injected into the authorized keys file.
So, I know pipe (|) takes the output to its left and feeds it to the command to the right hand side of it. But normally we use cat command like this:
cat "content_to_be_added" >> file_to_be_appended
so, if I'm not mistaken, contents of id_rsa.pub
should get injected right before >> in order for this to work. So, how does this function exactly and why?
By the way, please feel free to correct my terminology. I'd also appreciate if you can tell me if this operator here >>
has a specific name.
ssh-copy-id
. – Panki May 05 '20 at 13:06>>
is a redirection operator. See for example What are the shell's control and redirection operators? – steeldriver May 05 '20 at 13:09