fakeserver icon indicating copy to clipboard operation
fakeserver copied to clipboard

What is the password once docker is installed and the command is executed?

Open raycelgraterol opened this issue 2 years ago • 3 comments

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.

image

Please help me with this.

raycelgraterol avatar Oct 15 '23 01:10 raycelgraterol

Same issue. @raycelgraterol Did you find the password?

sagarsanjaysutar avatar Jan 12 '25 07:01 sagarsanjaysutar

I figured this out with the help of ChatGPT.

  1. 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
    
  2. At this step, do not run the ./up script. 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
    
  3. It turns out that the permission on the .authorized_keys file 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" 
    
  4. It is still not over because the above set permission gets reset when you run ./up script. This is related to docker mounting/binding process. So now the ./up script 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
    
    
  5. Now run the ./up script to create the docker container.

  6. Inside the container there is /etc/ssh/sshd_config file that needs to be edited. This config file has 2 lines that needs to be changed.

    1. From #PasswordAuthentication yes -> PasswordAuthentication no. This is so that the password prompt is disabled.
    2. From AuthorizedKeysFile .ssh/authorized_keys /etc/authorized_keys/%u to AuthorizedKeysFile /etc/authorized_keys/app so 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
    
  7. Now connect to the container using the following

    ubuntu@ubuntu: ssh app@<container-ip> -i ~/.ssh/id_rsa -o IdentitiesOnly=yes
    

sagarsanjaysutar avatar Jan 13 '25 20:01 sagarsanjaysutar

Its constantly asking for password. What's the password?

bikashg avatar Feb 02 '25 20:02 bikashg