通过ssh键连接SFTP服务器

时间:2020-05-04 20:25:59

标签: docker ssh rsa sftp

我想在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

我无法想象是什么问题?

1 个答案:

答案 0 :(得分:0)

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

或像这样执行ssh:

ssh -o StrictHostKeyChecking=no foo@localhost