Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following command puts the content of the local id_rsa.pub into the authorized_keys file on the host.

But I don't quite understand how cat and | works together to achieve this goal, can someone explain?

cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
share|improve this question
Just wanted to point out the UUOC (useless use of cat). ssh b@B 'cat >> .ssh/authorized_keys' < .ssh/id_rsa.pub is better. – jw013 Apr 7 '12 at 3:17
Good point. Thx @jw013 – mitnk Apr 7 '12 at 4:29
up vote 2 down vote accepted

The cat command outputs contents of the file .ssh/id_rsa.pub; the | (pipe) receives this text output and then sends (i.e. pipes) the text to ssh.

Then, ssh uses this text as input for the cat >> .ssh/authorized_keys command.

share|improve this answer
Thanks @Renan. Now I think I understand. – mitnk Apr 7 '12 at 4:28
I think this command can be clear if we ignore ssh part ssh b@B. It will become: cat .ssh/id_rsa.pub | cat >> .ssh/authorized_keys, which I can understand. ;) – mitnk Apr 7 '12 at 4:33
@mitnk pretty much that, if you see that the cat after the pipe is running on the other machine. – Renan Apr 7 '12 at 4:35

For cat command if no file name is provided it takes it from stdin. In this case its the output of the |.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.