sshfs 给出“远程主机已断开连接”

sshfs 给出“远程主机已断开连接”

我正在尝试sftp使用以下命令将连接安装到文件夹中sshfs,但出现错误。

~$ sshfs [email protected]:/ testfo
remote host has disconnected

如果我通过 SSH 进入系统并重复该命令,则会发生相同的错误localhost。此命令也适用于另一台机器,因此问题出在服务器上的某个地方。

~$ cat /var/log/auth.log

[...]

May 24 22:49:43 example sshd[20095]: Accepted publickey for admin from 24.111.222.33 port 47086 ssh2: RSA ad:xx:6e:xx:14:xx:bd:b5:xx:cb:66:xx:xx:xx:a3:ac
May 24 22:49:43 example sshd[20095]: pam_unix(sshd:session): session opened for user admin by (uid=0)
May 24 22:49:43 example systemd-logind[812]: Removed session 60.
May 24 22:49:43 example systemd-logind[812]: New session 61 of user admin.
May 24 22:49:44 example sshd[20143]: Received disconnect from 24.203.164.45: 11: disconnected by admin
May 24 22:49:44 example sshd[20095]: pam_unix(sshd:session): session closed for user admin

~/.ssh目录归管理员所有,因为我认为这是针对类似问题的调试尝试。

供将来参考的其他信息:

问题是不是SSH 本身不行,但 SFTP 不行。这表现在 SSH 连接可以正常工作,但 SFTP 总是失败。尝试使用 SFTP 会导致Received unexpected end-of-file from SFTP server

问题是不是与登录脚本输出的字符串相关(例如~/.bashrc)。

所有用户(包括 root)都存在此问题。

这是我的 sshd 配置(/etc/ssh/sshd_config):

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

sftp-server软件包已安装。(sudo apt-get install openssh-sftp-server

答案1

老问题了,但这是针对这个问题提出的第一个问题。

我的问题是服务器需要密钥认证,但是我正在使用sudo并指定运行命令-o IdentityFile=~/.ssh/id_rsa,这意味着~扩展到 root 的主目录,而不是我的。

指定完整路径有效,我想使用$HOME也会有效(因为它会更早扩展)。

答案2

您的Subsystemsshd_config是错误的。

应该是Subsystem sftp /usr/lib/openssh/sftp-serverinternal-sftp。尝试将 修改为该/etc/ssh/sshd_config值,然后重启 ssh 服务再试一次。

答案3

如果远程服务器运行的是 Dropbear 而不是 OpenSSH,则会收到此错误。

SSHFS 使用 SFTP,而 Dropbear 不提供 SFTP。因此,当您尝试使用它时,Dropbear 服务器会认为这是对其无法理解的子系统的请求,并断开连接。

从这里:https://unix.stackexchange.com/questions/363540/mount-a-filesystem-using-sshfs-using-the-dropbear-server-on-yocto-firmware

答案4

发生在我身上的另一个原因是dropbearmulti二进制文件本身缺少字符串/usr/libexec/sftp-server,该字符串在 DD-WRT 的版本 33600 左右丢失了。请检查所述二进制文件是否提到此文件,否则即使存在它也不会工作。我不得不使用版本 33525 中的二进制文件并制作一个启动器来杀死正常的错误 dropbear,然后运行这个。您创建一个名为指向的符号链接dropbeardropbearmulti您使用停止当前一个stopservice sshd,然后运行正在运行的那个。查看ps正确的参数是什么样的。最好将它放在 jffs 上(或将其解压到 /tmp),这样您仍然可以在umount任何驱动器上使用。

相关内容