naked-auto not handle ssh-copy-id correctly #484

Open
opened 2025-12-29 01:19:45 +01:00 by adam · 2 comments
Owner

Originally created by @xinnj on GitHub (Mar 23, 2023).

Use the command below to start a headless container and mount shared folder automatically:

docker run -d  --name osx \
    --device /dev/kvm \
    -p 50922:10022 \
    -v "${PWD}/mac_hdd_ng_auto_monterey.img:/image" \
    --privileged=true \
    -v "${PWD}/share:/mnt/hostshare" \
    -e TERMS_OF_USE=i_agree \
    -e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \
    -e USERNAME=user\
    -e PASSWORD=alpine \
    -e "OSX_COMMANDS=/bin/bash -c \"sudo -S mount_9p hostshare\"" \
    sickcodes/docker-osx:naked-auto

Then the log of the container shows it's stucked at ssh-copy-id step:

Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
(qemu) Disk is being copied between layers. Repeating until able to copy SSH key into OSX...
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
Disk is being copied between layers. Repeating until able to copy SSH key into OSX...
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arc1515h/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
Disk is being copied between layers. Repeating until able to copy SSH key into OSX...
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
Disk is being copied between layers. Repeating until able to copy SSH key into OSX...
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
Disk is being copied between layers. Repeating until able to copy SSH key into OSX...
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.

Find the root caulse at line 233 of file: Dockerfile.naked-auto

; until [[ "$(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1)" ]]; do \

The condition expression of until will be always false as ssh-copy-id will generate multi-line output as below:

[arch@101d92dbf174 .ssh]$ $(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1)
/usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub"
Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts.
bash: Number: command not found
[arch@101d92dbf174 .ssh]$ echo $?
127
Originally created by @xinnj on GitHub (Mar 23, 2023). Use the command below to start a headless container and mount shared folder automatically: ``` docker run -d --name osx \ --device /dev/kvm \ -p 50922:10022 \ -v "${PWD}/mac_hdd_ng_auto_monterey.img:/image" \ --privileged=true \ -v "${PWD}/share:/mnt/hostshare" \ -e TERMS_OF_USE=i_agree \ -e EXTRA="-virtfs local,path=/mnt/hostshare,mount_tag=hostshare,security_model=passthrough,id=hostshare" \ -e USERNAME=user\ -e PASSWORD=alpine \ -e "OSX_COMMANDS=/bin/bash -c \"sudo -S mount_9p hostshare\"" \ sickcodes/docker-osx:naked-auto ``` Then the log of the container shows it's stucked at ssh-copy-id step: > Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. (qemu) Disk is being copied between layers. Repeating until able to copy SSH key into OSX... /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Disk is being copied between layers. Repeating until able to copy SSH key into OSX... /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arc1515h/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Disk is being copied between layers. Repeating until able to copy SSH key into OSX... /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Disk is being copied between layers. Repeating until able to copy SSH key into OSX... /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Disk is being copied between layers. Repeating until able to copy SSH key into OSX... /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. Find the root caulse at line 233 of file: Dockerfile.naked-auto ``` ; until [[ "$(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1)" ]]; do \ ``` The condition expression of `until` will be always false as `ssh-copy-id` will generate multi-line output as below: ``` [arch@101d92dbf174 .ssh]$ $(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1) /usr/sbin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/arch/.ssh/id_docker_osx.pub" Warning: Permanently added '[127.0.0.1]:10022' (ED25519) to the list of known hosts. bash: Number: command not found [arch@101d92dbf174 .ssh]$ echo $? 127 ```
Author
Owner

@maskalix commented on GitHub (Mar 28, 2023):

any way to solve?

@maskalix commented on GitHub (Mar 28, 2023): any way to solve?
Author
Owner

@xinnj commented on GitHub (Mar 29, 2023):

I solved the problem by replacing code from 233 to 236:

; until [[ "$(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1)" ]]; do \
    echo "Disk is being copied between layers. Repeating until able to copy SSH key into OSX..." \
    ; sleep 1 \
; done \

with code:

; while :; do \
    sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1 > /dev/null \
    ; if [[ "$?" == '0' ]]; then \
        break \
    ; else \
        echo "Disk is being copied between layers. Repeating until able to copy SSH key into OSX..." \
        ; sleep 1 \
    ; fi \
; done \
@xinnj commented on GitHub (Mar 29, 2023): I solved the problem by replacing code from 233 to 236: ``` ; until [[ "$(sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1)" ]]; do \ echo "Disk is being copied between layers. Repeating until able to copy SSH key into OSX..." \ ; sleep 1 \ ; done \ ``` with code: ``` ; while :; do \ sshpass -p${PASSWORD:=alpine} ssh-copy-id -f -i ~/.ssh/id_docker_osx.pub -p 10022 ${USERNAME:=user}@127.0.0.1 > /dev/null \ ; if [[ "$?" == '0' ]]; then \ break \ ; else \ echo "Disk is being copied between layers. Repeating until able to copy SSH key into OSX..." \ ; sleep 1 \ ; fi \ ; done \ ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Docker-OSX#484