sftp
sftp copied to clipboard
Single user with multiple keys causes malformed authorized_keys file
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.
I have the same thing here: two public keys for one user, mounted into .ssh/keys directory. And everythings works fine.
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.
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.