Запустите Alpine Linux в Docker с
docker run -it alpine
Выполнить следующие команды в контейнере: установить openssh, сгенерировать ключ, авторизовать ключ, попробовать подключиться :
apk add --no-cache --update openssh
/usr/bin/ssh-keygen -A ## For Alpine only, not for Ubuntu
ssh-keygen -o -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys
/usr/sbin/sshd
ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts; chmod 600 ~/.ssh/known_hosts
ssh -vv -oPasswordAuthentication=no localhost echo test
Выход:
...
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Trying private key: /root/.ssh/id_xmss
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
root@localhost: Permission denied (publickey,password,keyboard-interactive).
То же самое для Ubuntu docker run -it ubuntu
работает отлично:
apt-get update -qyy && apt install -qyy --no-install-recommends
openssh-server openssh-client ca-certificates
ssh-keygen -o -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys
mkdir -p /run/sshd ## Ubuntu only, fix a bug
/usr/sbin/sshd
ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts; chmod 600 ~/.ssh/known_hosts
ssh -vv -oPasswordAuthentication=no localhost echo test
выход
test
Что не так с Alpine? или с моей последовательностью команд на Alpine?
Upd: Это с Docker на Mac .
Upd2: последовательность в одной строке от @KamilCuk:
docker run -ti alpine sh -x -c 'apk add --no-cache --update openssh; /usr/bin/ssh-keygen -A; ssh-keygen -o -t rsa -b 4096 -f ~/.ssh/id_rsa -P ""; cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys; /usr/sbin/sshd; ssh-keyscan -t rsa localhost >>~/.ssh/known_hosts; chmod 600 ~/.ssh/known_hosts; ssh -oPasswordAuthentication=no localhost echo test'