我的服务器是 Ubuntu 14.04.5 LTS,我可以通过 SSH 使用 PuTTY 连接,但无法通过 WinSCP 连接。
当我尝试通过 WinSCP 连接时,出现错误:
连接已意外关闭。服务器发送命令退出状态 127
下面是一个日志文件
. 2019-01-23 15:40:22.694 --------------------------------------------------------------------------
. 2019-01-23 15:40:22.694 WinSCP Version 5.13.7 (Build 9125) (OS 6.1.7601 Service Pack 1 - Windows 7 Professional)
. 2019-01-23 15:40:22.694 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2019-01-23 15:40:22.695 Log level: Normal
. 2019-01-23 15:40:22.695 Local account: D146\Subhash
. 2019-01-23 15:40:22.695 Working directory: C:\Program Files (x86)\WinSCP
. 2019-01-23 15:40:22.695 Process ID: 6672
. 2019-01-23 15:40:22.696 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe"
. 2019-01-23 15:40:22.696 Time zone: Current: GMT+5:30 (India Standard Time), No DST
. 2019-01-23 15:40:22.696 Login time: 23 January 2019 PM 3:40:22
. 2019-01-23 15:40:22.696 --------------------------------------------------------------------------
. 2019-01-23 15:40:22.696 Session name: winscp testing (Site)
. 2019-01-23 15:40:22.696 Host name: 71.6.186.24 (Port: 22)
. 2019-01-23 15:40:22.697 User name: root (Password: Yes, Key file: No, Passphrase: No)
. 2019-01-23 15:40:22.697 Tunnel: No
. 2019-01-23 15:40:22.697 Transfer Protocol: SFTP
. 2019-01-23 15:40:22.697 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-01-23 15:40:22.697 Disable Nagle: No
. 2019-01-23 15:40:22.697 Proxy: None
. 2019-01-23 15:40:22.697 Send buffer: 262144
. 2019-01-23 15:40:22.697 SSH protocol version: 2; Compression: No
. 2019-01-23 15:40:22.697 Bypass authentication: No
. 2019-01-23 15:40:22.697 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-01-23 15:40:22.697 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom:
. 2019-01-23 15:40:22.697 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-01-23 15:40:22.697 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-01-23 15:40:22.697 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-01-23 15:40:22.697 Simple channel: Yes
. 2019-01-23 15:40:22.697 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-01-23 15:40:22.697 Shell: default
. 2019-01-23 15:40:22.697 EOL: LF, UTF: Auto
. 2019-01-23 15:40:22.697 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-01-23 15:40:22.697 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2019-01-23 15:40:22.697 SFTP Bugs: Auto,Auto
. 2019-01-23 15:40:22.697 SFTP Server: default
. 2019-01-23 15:40:22.698 Local directory: C:\Users\Subhash\Documents, Remote directory: /, Update: Yes, Cache: Yes
. 2019-01-23 15:40:22.698 Cache directory changes: Yes, Permanent: Yes
. 2019-01-23 15:40:22.698 Recycle bin: Delete to: No, Overwritten to: No, Bin path:
. 2019-01-23 15:40:22.698 DST mode: Unix
. 2019-01-23 15:40:22.698 --------------------------------------------------------------------------
. 2019-01-23 15:40:22.722 Looking up host "71.6.186.24" for SSH connection
. 2019-01-23 15:40:22.722 Connecting to 71.6.186.24 port 22
. 2019-01-23 15:40:22.977 We claim version: SSH-2.0-WinSCP_release_5.13.7
. 2019-01-23 15:40:23.234 Server version: SSH-2.0-OpenSSH_6.0p1 Debian-4+deb7u2
. 2019-01-23 15:40:23.235 We believe remote version has SSH-2 channel request bug
. 2019-01-23 15:40:23.235 Using SSH protocol version 2
. 2019-01-23 15:40:23.235 Have a known host key of type ecdsa-sha2-nistp256
. 2019-01-23 15:40:23.491 Doing ECDH key exchange with curve nistp256 and hash SHA-256
. 2019-01-23 15:40:23.822 Server also has ssh-dss/ssh-rsa host keys, but we don't know any of them
. 2019-01-23 15:40:23.822 Host key fingerprint is:
. 2019-01-23 15:40:23.822 ecdsa-sha2-nistp256 256 f0:39:24:5c:63:12:5a:0d:e3:35:08:3d:91:d2:9f:53 7HbkGPzNm6tuAiqUoEpiHX4jxoNzxJgXQjWOgjuKGM8=
. 2019-01-23 15:40:23.871 Host key matches cached key
. 2019-01-23 15:40:23.871 Initialised AES-256 SDCTR client->server encryption
. 2019-01-23 15:40:23.871 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2019-01-23 15:40:23.871 Initialised AES-256 SDCTR server->client encryption
. 2019-01-23 15:40:23.871 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2019-01-23 15:40:24.426 Using username "root".
. 2019-01-23 15:40:24.744 Server offered these authentication methods: publickey,password,keyboard-interactive
. 2019-01-23 15:40:24.745 Attempting keyboard-interactive authentication
. 2019-01-23 15:40:25.002 Server refused keyboard-interactive authentication
. 2019-01-23 15:40:25.002 Server offered these authentication methods: publickey,password,keyboard-interactive
. 2019-01-23 15:40:25.002 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2019-01-23 15:40:25.002 Using stored password.
. 2019-01-23 15:40:25.059 Sent password
. 2019-01-23 15:40:25.331 Access granted
. 2019-01-23 15:40:25.331 Opening session as main channel
. 2019-01-23 15:40:25.585 Opened main channel
. 2019-01-23 15:40:26.134 Started a shell/command
. 2019-01-23 15:40:26.148 --------------------------------------------------------------------------
. 2019-01-23 15:40:26.148 Using SFTP protocol.
. 2019-01-23 15:40:26.149 Doing startup conversation with host.
. 2019-01-23 15:40:26.149 Server sent command exit status 127
. 2019-01-23 15:40:26.150 Disconnected: All channels closed
* 2019-01-23 15:40:26.187 (EFatal) **Connection has been unexpectedly closed.** Server sent command exit status 127.
答案1
要从其他主机访问您的 sftp,请确保以下内容已安装并正确配置。
- 已安装的 OpenSSH 服务器
- 已配置sshd_配置
- 公钥认证 是
- 子系统 sftp internal-sftp
将您的公钥添加到 ~/.ssh/authorized_keys
启动 ssh 服务器并打开 22/TCP 端口
# /etc/init.d/sshd start
# iptables -I INPUT -j ACCEPT -p tcp --dport 22
最后,测试
$ sftp <login>@<hostname>