![背景](https://linux22.com/image/620595/%E8%83%8C%E6%99%AF.png)
我知道这个话题已经被讨论过很多次了,我几乎为自己还没有找到解决问题的方法而感到羞愧。显然有些事情我不太明白,如果能得到任何意见或指点,我将不胜感激。
背景
- Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
- 所有命令都以 root 身份运行,并且 ssh 密钥已复制到远程的 .ssh/authorized_keys
- 使用 ssh-agent 解锁密钥
- 正常的 sshfs cmd 工作正常 -
sshfs USER@REMOTE:/ /mnt/ssh/backup
- 将条目添加到 fstab 并执行“mount -a”按预期工作 -
sshfs#USER@REMOTE:/ /mnt/ssh/backup/ fuse defaults 0 0
#:自动挂载-V
Linux automount version 5.0.7
Directories:
config dir: /etc/default
maps dir: /etc
modules dir: /usr/lib/x86_64-linux-gnu/autofs
Compile options:
ENABLE_FORCED_SHUTDOWN ENABLE_IGNORE_BUSY_MOUNTS WITH_HESIOD
WITH_LDAP WITH_SASL LIBXML2_WORKAROUND
#:自动挂载-m
autofs dump map information
===========================
global options: none configured
Mount point: /mnt/ssh
source(s):
instance type(s): file
map: /etc/auto.sshfs
backup | -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
自动主控
/mnt/ssh /etc/auto.sshfs --timeout=30,--ghost,--debug
自动.sshfs
backup -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
当我在前台自动挂载 auto.master 时(如下所述),会创建“备份”文件夹,并且远程目录会毫无问题地挂载。我可以 ls -al /mnt/ssh/backup 文件夹,并且确实正在浏览远程主机
#:automount -f -v -d auto.master
#:ls -al /mnt/ssh/backup
attempting to mount entry /mnt/ssh/backup
lookup_mount: lookup(file): looking up backup
lookup_mount: lookup(file): backup -> -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
parse_mount: parse(sun): expanded entry: -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
parse_mount: parse(sun): gathered options: fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536
parse_mount: parse(sun): dequote(":sshfs#USER@REMOTE:/") -> :sshfs#USER@REMOTE:/
parse_mount: parse(sun): core of entry: options=fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536, loc=:sshfs#USER@REMOTE:/
sun_mount: parse(sun): mounting root /mnt/ssh, mountpoint backup, what sshfs#USER@REMOTE:/, fstype fuse, options rw,nodev,noatime,allow_other,default_permissions,max_read=65536
do_mount: sshfs#USER@REMOTE:/ /mnt/ssh/backup type fuse options rw,nodev,noatime,allow_other,default_permissions,max_read=65536 using module generic
mount_mount: mount(generic): calling mkdir_path /mnt/ssh/backup
mount_mount: mount(generic): calling mount -t fuse -s -o rw,nodev,noatime,allow_other,default_permissions,max_read=65536 sshfs#USER@REMOTE:/ /mnt/ssh/backup
spawn_mount: mtab link detected, passing -n to mount
mount_mount: mount(generic): mounted sshfs#USER@REMOTE:/ type fuse on /mnt/ssh/backup
但是,当我按照下面所述启动 autofs 服务时,“备份”文件夹会被创建,但是当我尝试 ls 该目录时,它却拒绝挂载。
#:service autofs start
#:ls -al /mnt/ssh/backup
attempting to mount entry /mnt/ssh/backup
lookup_mount: lookup(file): looking up backup
lookup_mount: lookup(file): backup -> -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
parse_mount: parse(sun): expanded entry: -fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536 :sshfs#USER@REMOTE:/
parse_mount: parse(sun): gathered options: fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536
parse_mount: parse(sun): dequote(":sshfs#USER@REMOTE:/") -> :sshfs#USER@REMOTE:/
parse_mount: parse(sun): core of entry: options=fstype=fuse,rw,nodev,noatime,allow_other,default_permissions,max_read=65536, loc=:sshfs#USER@REMOTE:/
sun_mount: parse(sun): mounting root /mnt/ssh, mountpoint backup, what sshfs#USER@REMOTE:/, fstype fuse, options rw,nodev,noatime,allow_other,default_permissions,max_read=65536
do_mount: sshfs#USER@REMOTE:/ /mnt/ssh/backup type fuse options rw,nodev,noatime,allow_other,default_permissions,max_read=65536 using module generic
mount_mount: mount(generic): calling mkdir_path /mnt/ssh/backup
mount_mount: mount(generic): calling mount -t fuse -s -o rw,nodev,noatime,allow_other,default_permissions,max_read=65536 sshfs#USER@REMOTE:/ /mnt/ssh/backup
spawn_mount: mtab link detected, passing -n to mount
>> read: Connection reset by peer
mount(generic): failed to mount sshfs#USER@REMOTE:/ (type fuse) on /mnt/ssh/backup
dev_ioctl_send_fail: token = 22
failed to mount /mnt/ssh/backup
我测试过许多解决方法,包括但不限于
- 退出 :sshfs#USER@REMOTE:/ -
:sshfs\#USER@REMOTE\:/
- 删除 / -
:sshfs#USER@REMOTE:
- 在 auto.sshfs 中提供我的身份文件的路径 -
IdentityFile=/root/.ssh/id_rsa
- 在 auto.master 中指定 uid/gid -
/mnt/ssh /etc/auto.sshfs uid=0,gid=0,--timeout=30,--ghost
我现在没有主意了,陷入困境。
提前致谢,JS
更新
@KaszpiR - 感谢您的努力,但正确的密钥已经上传到远程的authorized_keys文件,标准sftp或sshfs可以完美运行。
看来 autofs initscript(或脚本中用于启动自动挂载的选项之一)正在产生该问题,但还没有时间对其进行正确的调试。
作为一种解决方法,您可以完全删除 /etc/init.d/autofs 脚本(update-rc.d autofs 删除并将其移动到备份位置以进行安全保管)并手动或通过脚本启动自动挂载。
答案1
我遇到了同样的问题,连接到远程机器时必须从 root 用户添加 ssh 密钥,以允许无密码 ssh 登录:
sudo su -
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub remote_user@remote_server
尝试 ssh 到远程机器,系统不会要求您输入密码。
重新启动 autofs