如何让 Ubuntu 上的 SFTP 再次工作?我应该尝试修复它还是重新安装?

如何让 Ubuntu 上的 SFTP 再次工作?我应该尝试修复它还是重新安装?

更新:添加了另外两个日志的输出,现在只跟踪最后二十行......所以你可以 相关线路。


经过六个月的完美运行,我的 Ubuntu 机器上的 SFTP突然停止工作。我从未配置或安装过它,它只是起作用了。

  • Ubuntu 14.04.1 LTS,GNU bash,版本 4.3.11(1)-release (i686-pc-linux-gnu)

我使用 SFTP 的唯一方法是将我的服务器映射为 Windows 计算机上的字母驱动器,SFTP 网络驱动器 免费。正如上面链接的帖子中痛苦的细节所述,我还确认它不适用于网络驱动器(SFTP Net Drive 竞争对手)和文件齐拉。不过,我只使用过 SFTP Net Drive。

重要的是,我创建了一个新的临时帐户,并且我SFTP 与它,这意味着这是我当前帐户的 Ubuntu 配置问题。

我所做的唯一自定义是将别名和类似别名的函数添加到文件中.bashrc,并将几个新命令添加到.inputrc(例如这里,这里,这里, 和这里。如果任何与 SFTP 相关的设置被更改,那就是一次奇怪的事故。

我已经重新安装了 SFTP Net Drive,并重新启动了两台计算机,但仍然没有任何效果。

按照中的提示进行操作这个线程:

检查(通常在最后,尽管配置的顺序无关紧要)sftp 子系统是否已在 openssh-server 配置中定义且未注释掉。

cat /etc/ssh/sshd_config
Subsystem sftp /usr/lib/openssh/sftp-server

这正是那里。

并且还要检查子系统的文件是否存在

file /usr/lib/openssh/sftp-server
/usr/lib/openssh/sftp-server: ELF 32-bit

我的输出:

file /usr/lib/openssh/sftp-server
/usr/lib/openssh/sftp-server: ELF 32-bit LSB  shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=469f88be752153898a1e5a4787e6145e6eb99bd3, stripped
history -a

检查文件是否设置了读取和可执行标志

ls -l /usr/lib/openssh/sftp-server
-rwxr-xr-x 1 root root 63484 2009-10-22 22:36 /usr/lib/openssh/sftp-server

权限是完全一样的。

检查日志中的错误消息

tail -20 /var/log/auth.log
tail -20 /var/log/messages.log

我尝试在晚上9:39使用SFTP Net Drive登录,然后输出日志。

auth.log:

sudo tail -20 /var/log/auth.log
Jan 14 21:37:18 myservername sudo: pam_unix(sudo:session): session closed for user root
Jan 14 21:38:27 myservername sshd[3068]: Invalid user admin from 123.45.67.891
Jan 14 21:38:27 myservername sshd[3068]: input_userauth_request: invalid user admin [preauth]
Jan 14 21:38:27 myservername sshd[3068]: pam_unix(sshd:auth): check pass; user unknown
Jan 14 21:38:27 myservername sshd[3068]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=li707-40.members.linode.com
Jan 14 21:38:28 myservername sshd[3068]: Failed password for invalid user admin from 123.45.67.891 port 45702 ssh2
Jan 14 21:38:29 myservername sshd[3068]: Received disconnect from 123.45.67.891: 11: Bye Bye [preauth]
Jan 14 21:38:40 myservername sshd[3071]: Accepted password for myusername from 173.61.202.27 port 54007 ssh2
Jan 14 21:38:40 myservername sshd[3071]: pam_unix(sshd:session): session opened for user myusername by (uid=0)
Jan 14 21:38:43 myservername sshd[3071]: pam_unix(sshd:session): session closed for user myusername
Jan 14 21:38:49 myservername sudo:    myusername : TTY=pts/0 ; PWD=/home/myusername ; USER=root ; COMMAND=/usr/bin/tail -50 /var/log/syslog
Jan 14 21:38:49 myservername sudo: pam_unix(sudo:session): session opened for user root by myusername(uid=0)
Jan 14 21:38:49 myservername sudo: pam_unix(sudo:session): session closed for user root
Jan 14 21:40:01 myservername CRON[3151]: pam_unix(cron:session): session opened for user smmsp by (uid=0)
Jan 14 21:40:01 myservername CRON[3151]: pam_unix(cron:session): session closed for user smmsp
Jan 14 21:41:00 myservername sudo:    myusername : TTY=pts/0 ; PWD=/home/myusername ; USER=root ; COMMAND=/usr/bin/tail -20 /var/log/auth.log
Jan 14 21:41:00 myservername sudo: pam_unix(sudo:session): session opened for user root by myusername(uid=0)
Jan 14 21:41:00 myservername sudo: pam_unix(sudo:session): session closed for user root
Jan 14 21:41:17 myservername sudo:    myusername : TTY=pts/0 ; PWD=/home/myusername ; USER=root ; COMMAND=/usr/bin/tail -50 /var/log/auth.log
Jan 14 21:41:17 myservername sudo: pam_unix(sudo:session): session opened for user root by myusername(uid=0)
history -a

sudo tail -20 /var/log/syslog:

sudo tail -20 /var/log/syslog
Jan 14 17:56:39 myservername /usr/sbin/irqbalance: Balancing is ineffective on systems with a single cache domain.  Shutting down
Jan 14 17:56:43 myservername sm-mta[981]: starting daemon (8.14.4): SMTP+queueing@00:10:00
Jan 14 17:56:46 myservername ntpdate[465]: step time server 91.189.89.199 offset 1.521544 sec
Jan 14 17:57:02 myservername ntpdate[1074]: adjust time server 91.189.89.199 offset 0.000019 sec
Jan 14 17:57:59 myservername kernel: [   83.690027] random: nonblocking pool is initialized
Jan 14 18:00:01 myservername CRON[1183]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 18:17:01 myservername CRON[1438]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 14 18:20:01 myservername CRON[1536]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 18:40:01 myservername CRON[1971]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 19:00:01 myservername CRON[2086]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 19:17:01 myservername CRON[2187]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 14 19:20:01 myservername CRON[2204]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 19:40:01 myservername CRON[2317]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 20:00:01 myservername CRON[2432]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 20:17:01 myservername CRON[2531]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 14 20:20:01 myservername CRON[2548]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 20:40:01 myservername CRON[2663]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 21:00:01 myservername CRON[2843]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
Jan 14 21:17:01 myservername CRON[2942]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Jan 14 21:20:01 myservername CRON[2959]: (smmsp) CMD (test -x /etc/init.d/sendmail && /usr/share/sendmail/sendmail cron-msp)
history -a

$ sudo tail -20 /var/log/messages.log

sudo tail -20 /var/log/messages.log
tail: cannot open ‘/var/log/messages.log’ for reading: No such file or directory
history -a

我不知道这意味着什么。接受我帐户的密码,但不接受 root 的密码。我从 1Password 复制密码,将其粘贴到控制台中,它就可以工作了。然后将其粘贴到 SFTP 网络驱动器中,但没有。

我还注意到日志中前面出现了“无法加载主机密钥”错误,并且这一页说要执行ssh-keygen -A,我就这么做了。我不明白这是否有什么不同。


这是我应该尝试解决的问题吗?或者我应该再次“重新安装”SFTP? (尽管我一开始就没有安装过它。)

答案1

事实证明,如果任何文本输出到控制台,SFTP 就会崩溃。我在我的 中添加了一个 echo ~/.bashrc,这杀死了它。

我已将以下内容添加到最顶部.bashrc

:<<COMMENT
  SFTP breaks if any thing is output to the shell, and it doesn't need
  anything in .bashrc anyway.

  Description of the following line of code: "If file descriptor 0, or 
  'the input' is connected to a terminal, which is true when you do: 
     ssh yourhost 
  but not when you do:
     ssh yourhost bash -s < script # here it's connected to 'script', a file"

  See
  - https://serverfault.com/questions/485487/use-bashrc-without-breaking-sftp
  - http://www.openssh.com/faq.html#2.9
COMMENT
[ -t 0 ] || return

此外,我已将 echo(我打算将其作为登录介绍消息)移至/etc/motd,如中所述这个答案


感谢 #ba​​sh 上的 Dualbus 和 Ishikawa。

相关内容