sftp icon indicating copy to clipboard operation
sftp copied to clipboard

Single user with multiple keys causes malformed authorized_keys file

Open geraldcor opened this issue 6 years ago • 3 comments

This relates to #110 and #111 I do not believe that PR fixed this issue. I still get a malformed authorized_keys file and now the server will not authenticate due to stricter parsing.

I will attach a PR for a proposed fix.

geraldcor avatar Feb 14 '19 21:02 geraldcor

I have the same thing here: two public keys for one user, mounted into .ssh/keys directory. And everythings works fine.

cdaller avatar May 13 '19 15:05 cdaller

This is indeed still an issue for me as well, the suggested approach works.

I encountered this issue due to my ansible script:

- name: Setup authorized_keys
  copy:
    dest: "/opt/sftp/keys/{{ item.split(' ')[2] }}"
    content: "{{ item }}"
  with_items: "{{ sftp_keys }}"

This creates files with one public key on the first line without any newline at the end.

cat does not add newlines, neither does bash when using >> It's actually echo which adds a newline to the input string by default.

Autom3 avatar Jun 27 '19 15:06 Autom3

The current approach works IF the files ends with a new line.

Since it's common on linux for files to not have a newline char at the end of the file the cat >> approach does not work.

Easiest workaround is to add newlines to the public key files, but this should really be fixed by adding echo >> "/home/$user/.ssh/authorized_keys" in each loop.

Edit: Ah, I now see that there is someone that have done just that but you suggested a different fix. I've created a PR for it since the other commit wasn't one.

gangefors avatar Jan 23 '21 09:01 gangefors