ssh-copy-id no newline bug

Philip Hands
2016-03-22T08:17:21Z

Gert Doering <gert at greenie.muc.de> writes:

> Hi,
>
> On Tue, Mar 22, 2016 at 08:34:46AM +0100, Philip Hands wrote:
>> I think that adding the following, just before the 'mkdir
.ssh', should
>> do the trick:
>>
>>   [ "`tail -c1 .ssh/authorized_keys 2>/dev/null`" ]
&& echo > .ssh/authorized_keys ;
>>
>> anyone know of portability issues with that?
>
> I'm not sure what the test will do, but the "echo" should be
an
> "echo >>", no?

Yes. Doh! ;-)

The test gets the last character of the file, and puts it in quotes
after removing new-lines -- which basically means that test fails if
there's a newline there, or if the file's empty, since that gives you:

 [ "" ]

which means that the second half of the && does not need to be
evaluated -- the result being that a newline is only added if the last
character of the file is not already a newline.

The only thing that's wrong with that is if the file is empty it'll end
up with a blank line at the start, but a) why would there be an empty
file there? and b) who cares?

Cheers, Phil.
--
|)|  Philip Hands  [+44 (0)20 8530 9560]  HANDS.COM Ltd.
|-|  http://www.hands.com/    http://ftp.uk.debian.org/
|(|  Hugo-Klemm-Strasse 34,   21075 Hamburg,    GERMANY
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL:
<http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20160322/2125d3e8/attachment-0001.bin>