sftp icon indicating copy to clipboard operation
sftp copied to clipboard

Multiple keys are added to authorized_keys without line breaks

Open asostechnix opened this issue 4 years ago • 5 comments

I am running atmoz/sftp:alpine in Azure Container Instances.

I have two RSA public keys for the same user, which are mounted as a secret volume into /home/username/.ssh/keys

The file /home/username/.ssh/authorized_keys does contain both keys once the container is running but without a line break between them, which causes key auth to fail.

I have tried adding a single line break to the end of the secrets in the volume definition but it didn't make a difference.

asostechnix avatar Sep 16 '21 09:09 asostechnix

We have the same issue. A manual insertion of a line break in the /home/username/.ssh/authorized_keys file between the keys has solved the login issue.

TobiTh avatar Sep 30 '21 14:09 TobiTh

Same issue here, building a Helm chart using this base image and running into the issue. Helm strips out any whitespaces so its even more difficult to add them in. Confirming this is an issue so I will look at the code to submit a PR if I can make the time today.

jalleyne avatar Nov 10 '21 20:11 jalleyne

I have a working fix that forces a new line with this proposed change. Does anyone see any concerns with this update?

Suggested fix:

echo -e "$(cat "$publickey")" >> "$userKeysAllowedFileTmp"

Existing read and append code: https://github.com/atmoz/sftp/blob/302390e67cdd589702f887ddbf0ea7b2d9a877aa/files/create-sftp-user#L89-L91

jalleyne avatar Nov 11 '21 02:11 jalleyne

@jalleyne i needed to build the image from repo because there is no ARM image in Docker hub. I can confirm that your change fixed the key files error that was causing container to fail on init. Thank you. It works with the latest alpine

aiac avatar Mar 30 '22 12:03 aiac

For anyone else hitting this when deploying via config map here is a hack that allows multiple public keys to be supplied.

apiVersion: v1
kind: ConfigMap
metadata:
  name: sftp-public-keys
data:
  # both keys listed in single file
  keys.txt: |
    ssh-rsa AAAAB3Nz...3u8D
    ssh-rsa AAAAB3Nz...JQ0pz

tmakin avatar Apr 12 '22 21:04 tmakin