What is the password once docker is installed and the command is executed?
What is the password once docker is installed and the command is executed?
I run ssh app@localhost -p 2222 and it need a password.
Please help me with this.
Same issue. @raycelgraterol Did you find the password?
I figured this out with the help of ChatGPT.
-
First, I followed the steps in the README. Note: For the 3rd command to work, you have to generate an SSH key using
ssh-keygen -t rsa -b 4096 -C "[email protected]"ubuntu@ubuntu: git clone <https://github.com/kabirbaidhya/fakeserver.git> ubuntu@ubuntu: cd fakeserver ubuntu@ubuntu: cat ~/.ssh/id_rsa.pub > .authorized_keys -
At this step, do not run the
./upscript. There a lot of things that we need to get right before creating the docker container. If you have accidently creatred the docker container, then delete it using the following:ubuntu@ubuntu: docker stop fakeserver ubuntu@ubuntu: docker rm fakeserver ubuntu@ubuntu: docker image rm <fakeserver_image_id> -f -
It turns out that the permission on the
.authorized_keysfile in the project dir. is wrong. As per the official website of SSH & ChatGPT, the following permission needs to be added.ubuntu@ubuntu: sudo chmod 600 "$(pwd)/.authorized_keys" ubuntu@ubuntu: sudo chown 1001:1001 "$(pwd)/.authorized_keys" -
It is still not over because the above set permission gets reset when you run
./upscript. This is related to docker mounting/binding process. So now the./upscript needs to be modified to the following so we get finner control over the mounting permission:#!/bin/sh docker run -d \\ -p 2222:22 \\ --mount type=bind,source="$(pwd)/.authorized_keys",target=/etc/authorized_keys/app,readonly \\ --mount type=bind,source="$(pwd)/.host_keys",target=/etc/ssh/keys \\ -e SSH_USERS="app:1001:1001" \\ --name fakeserver kabirbaidhya/fakeserver -
Now run the
./upscript to create the docker container. -
Inside the container there is
/etc/ssh/sshd_configfile that needs to be edited. This config file has 2 lines that needs to be changed.- From
#PasswordAuthentication yes->PasswordAuthentication no. This is so that the password prompt is disabled. - From
AuthorizedKeysFile .ssh/authorized_keys /etc/authorized_keys/%utoAuthorizedKeysFile /etc/authorized_keys/appso that only our authorized_key is used which we copied over in Point 1, 3rd command.
These changes can be made using the following command.
ubuntu@ubuntu: docker exec -it fakeserver sh -c "sed -i 's|^AuthorizedKeysFile.*|AuthorizedKeysFile /etc/authorized_keys/app|' /etc/ssh/sshd_config" ubuntu@ubuntu: docker exec -it fakeserver sh -c "sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config" ubuntu@ubuntu: docker restart fakeserver - From
-
Now connect to the container using the following
ubuntu@ubuntu: ssh app@<container-ip> -i ~/.ssh/id_rsa -o IdentitiesOnly=yes
Its constantly asking for password. What's the password?