Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In order to pass the contents of one file to another we can, for example:

cat ~/temp_minhakey.pub >> ~/.ssh/authorized_keys

Let's say, we need to append more content to authorized_keys, but we don't want to overwrite it.

Should we use cat again for the next keys ? Or should we flag with something specific ?

Thanks in advance.

share|improve this question

2 Answers 2

up vote 8 down vote accepted
cat ~/temp_minhakey.pub >> ~/.ssh/authorized_keys

appends the contents of ~/temp_minhakey.pub to ~/.ssh/authorized_keys, it does not overwrite it. This is safe.

You might be confused with a single > which overwrites the file. The next command will overwrite your authorized_keys file:

cat somefile > ~/.ssh/authorized_keys
share|improve this answer

The last part of that command has nothing to do with cat; the >> is a shell redirect that will always append to whatever target file you are specifying. If you used > instead, then it would overwrite the file.

There are several other shell redirects, and you will be more productive on a command line if you learn what they all are and when to use them:

http://www.gnu.org/software/bash/manual/bashref.html#Redirections

share|improve this answer

Your Answer

 
discard

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.