Search code examples
bashdockercontainerssftp

How to use atmoz/sftp?


https://github.com/atmoz/sftp I am trying to set this up for testing and I have attempted to follow the README with no luck. I need to log in with ssh keys but the directions but it keeps asking me for a password. I am not setting a password when the keys get generated.

/home/test/sftp_testing
$ ls
test1.txt  test2.txt  test3.txt  testing4.txt
$ ssh-keygen -t ed25519 -f ssh_host_ed25519_key < /dev/null
$ ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key < /dev/null
$ ls
ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub  test1.txt  test2.txt  test3.txt  testing4.txt
$ docker run \
>     -v /home/test/sftp_testing/ssh_host_ed25519_key:/etc/ssh/ssh_host_ed25519_key \
>     -v /home/test/sftp_testing/ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key \
>     -v /home/test/sftp_testing/share:/home/foo/share \
>     -p 9000:22 -d atmoz/sftp \
>     foo::1001
$ docker ps
CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                                   NAMES
7e10e9d5a864   atmoz/sftp   "/entrypoint foo::10…"   4 seconds ago   Up 3 seconds   0.0.0.0:9000->22/tcp, :::9000->22/tcp   priceless_edison
$ sftp -P 9000 -i /home/test/sftp_testing/ssh_host_rsa_key -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null foo@10.0.2.15
Warning: Permanently added '[10.0.2.15]:9000' (ED25519) to the list of known hosts.
foo@10.0.2.15`'s password: 


Solution

  • So it looks like the instructions were not complete if you want to try to use a key. I was able to get it to work with the following:

    docker run \
        -v /home/test/sftp_testing/ssh_host_ed25519_key:/etc/ssh/ssh_host_ed25519_key \
        -v /home/test/sftp_testing/ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key \
        -v /home/test/sftp_testing/ssh_host_ed25519_key.pub:/home/foo/.ssh/keys/ssh_host_ed25519_key.pub:ro \
        -v /home/test/sftp_testing/ssh_host_rsa_key.pub:/home/foo/.ssh/keys/ssh_host_rsa_key.pub:ro \
        -v /home/test/sftp_testing/share:/home/foo/share \
        -p 9000:22 -d test_thing \
        foo::1001
    
    sftp -P 9000 -i /home/testing/sftp_testing/ssh_host_ed25519_key -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null foo@10.0.2.15