通过 ssh 密钥连接 SFTP 服务器

Connect SFTP Server by ssh key

我想在 docker 容器内的本地计算机上模拟 SFTP 服务器。

我找到了这张图片:https://github.com/atmoz/sftp

并根据图像的 github 页面准备了这个 docker-compose 文件。

我的docker-compose 文件如下;

version: "3"

services:
  sftp:
    image: atmoz/sftp
    ports:
      - "2222:22"
    command: foo:pass:1001
    volumes:
      - /$HOME/ftp-server-storage:/home/foo/upload
      - ./../../src/main/resources/ssh-key/app_ssh_key.pub:/home/foo/.ssh/keys/id_rsa.pub:ro
    networks:
      - sam_network

networks:
  sam_network:
    driver: bridge

而且我已经用这个命令生成了 RSA 密钥对;

ssh-keygen -b 4096 -t rsa -f app_ssh_key

在那之后我希望用那个命令连接服务器;

sftp -P 2222 -oIdentityFile=app_ssh_key foo@localhost

注意;我为此参数传递了私钥文件; -oIdentityFile=app_ssh_key

但是我收到了这个错误;

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:EEzFNVY6jLOSg0gJyprSz6AZKlgar+gHZkreQnaNOeo.
Please contact your system administrator.
Add correct host key in /Users/sam/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /Users/sam/.ssh/known_hosts:2
ED25519 host key for [localhost]:2222 has changed and you have requested strict checking.
Host key verification failed.
Connection closed

我想不出是什么问题?

尝试删除文件/Users/sam/.ssh/known_hosts

或者像这样执行ssh:

ssh -o StrictHostKeyChecking=no foo@localhost