AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 519613
Accepted
Stephen Boston
Stephen Boston
Asked: 2019-05-18 16:56:08 +0800 CST2019-05-18 16:56:08 +0800 CST 2019-05-18 16:56:08 +0800 CST

如何在非标准 SSH 端口上为 sshfs 创建 fstab 条目并使用 ssh 密钥

  • 772

服务器正在侦听端口“8765”并需要 SSH 密钥进行身份验证。

我可以使用以下命令挂载远程目录:

sshfs -o idmap=user,port=8765 stephen@server:/export/usb2T /mnt/usb2T

服务器识别出我的 SSH 公钥。

我已经看到,作为标准 SSH 端口的 fstab 条目,这将是:

stephen@server:/export/inbox /mnt/inbox fuse.sshfs  defaults,_netdev  0  0 

但我需要添加服务器的监听端口和客户端用户的 SSH 公钥。

我怎么做?

fstab sshfs
  • 2 2 个回答
  • 12336 Views

2 个回答

  • Voted
  1. somethingSomething
    2019-05-18T20:24:48+08:002019-05-18T20:24:48+08:00

    /etc/fstab您要查找的条目是:

    使用,port=PORTNUMBERand,IdentityFile=/root.ssh/id_rsa选项:

      sshfs#USER@IP-ADDRESS:/export/inbox /mnt/inbox fuse.sshfs delay_connect,_netdev,user,IdentityFile=/root.ssh/id_rsa,idmap=user,allow_other,default_permissions,port=PORTNUMBER,uid=0,gid=0,rw,nosuid,nodev 0 0
    

    ssh通过SSHFS远程挂载目录

    • 通过设置 SSH 密钥(如上所述),您无需在安装时输入密码。这将使安装更加简单,甚至可以使用脚本或在您登录本地计算机时自动完成。
    • 与 SSH 一样,本地计算机和远程计算机之间的所有流量都是加密的。
    • 如果您是本地计算机的管理员,您可以将系统配置为在计算机启动时执行此操作,以便始终挂载它。您需要通过添加这样的一行来修改 /etc/fstab (不过都在一行上):
    • 您还需要设置 SSH 密钥来执行此操作,因此您不必输入密码。有关选项的说明,请参阅 SSHFS 手册页。如果您发现上面的 fstab 行不能正常工作(导致启动时出现错误消息),您可以将其修改为此(注意添加 noauto):

    sshfs#USER@IP-ADDRESS: /export/inbox fuse defaults,user,noauto,
    uid=einstein,gid=einstein,allow_other,IdentityFile=/home/alfred/.ssh/id_dsa 0 0 
    

    sshfs#USER@IP-ADDRESS: /export/inbox fuse defaults,user,uid=USER,gid=USER,allow_other,IdentityFile=/home/USER/.ssh/id_dsa 0 0   
    

    Mead 的安全外壳指南 (SSH)

    如何在 fstab 中挂载 sshfs 远程目录

    使用不带 mount -a 的 fstab 自动挂载 sshfs

    SSHFS 接受许多您可能想要检查的命令行选项。例如,如果远程计算机上的 SSH 服务器在端口 12345 而不是端口 22 上运行,您可以这样做:

    sshfs USER@IP-ADDRESS: /export/inbox -p PORTNUMBER
    

    以下是命令行选项:

    SSHFS 选项:

    -p PORT
        equivalent to '-o port=PORT' 
    -C
    
    equivalent to '-o compression=yes'
    -F ssh_configfile
        specifies alternative ssh configuration file 
    -1
    
    equivalent to '-o ssh_protocol=1'
    -o reconnect
        reconnect to server 
    -o delay_connect
        delay connection to server 
    -o sshfs_sync
        synchronous writes 
    -o no_readahead
        synchronous reads (no speculative readahead) 
    -o sshfs_debug
        print some debugging information 
    -o cache=BOOL
        enable caching {yes,no} (default: yes) 
    -o cache_timeout=N
        sets timeout for caches in seconds (default: 20) 
    -o cache_X_timeout=N
        sets timeout for {stat,dir,link} cache 
    -o workaround=LIST
        colon separated list of workarounds 
        none
    
        no workarounds enabled
    
        all
    
        all workarounds enabled 
        [no]rename 
    
    fix renaming to existing file (default: off)
    
        [no]nodelaysrv 
    
    set nodelay tcp flag in ssh (default: off)
    
        [no]truncate 
    
    fix truncate for old servers (default: off)
    
        [no]buflimit 
    
    fix buffer fillup bug in server (default: on)
    
    -o idmap=TYPE
        user/group ID mapping, possible types are: 
        none
    
        no translation of the ID space (default)
    
        user
    
        only translate UID of connecting user
    
        file
    
        translate UIDs/GIDs based upon the contents of uidfile and gidfile 
    -o uidfile=FILE
        file containing username:uid mappings for idmap=file 
    -o gidfile=FILE
        file containing groupname:gid mappings for idmap=file 
    -o nomap=TYPE
        with idmap=file, how to handle missing mappings 
        ignore
    
        don't do any re-mapping
    
        error
    
        return an error (default) 
    -o ssh_command=CMD
        execute CMD instead of 'ssh' 
    -o ssh_protocol=N
        ssh protocol to use (default: 2) 
    -o sftp_server=SERV
        path to sftp server or subsystem (default: sftp) 
    -o directport=PORT
        directly connect to PORT bypassing ssh -o slave communicate over stdin and stdout bypassing network 
    -o transform_symlinks
        transform absolute symlinks to relative 
    -o follow_symlinks
        follow symlinks on the server 
    -o no_check_root
        don't check for existence of 'dir' on server 
    -o password_stdin
        read password from stdin (only for pam_mount!) 
    -o SSHOPT=VAL
        ssh options (see man ssh_config) 
    

    人/1/sshfs

    • 11
  2. Best Answer
    Stephen Boston
    2019-05-20T09:11:39+08:002019-05-20T09:11:39+08:00

    我希望这个 sshfs 挂载到:

    1. 仅在实现网络连接后发生;
    2. 使挂载上的文件可执行。

    将 somethingSomething 的优秀帖子中提供的信息以及所需的选项汇总在一起,我们得到了:

    stephen@server:/export/inbox /mnt/inbox fuse.sshfs x-systemd.automount,x-systemd.requires=network-online.target,_netdev,user,idmap=user,transform_symlinks,port=2314,identityfile=/home/stephen/.ssh/id_rsa,allow_other,default_permissions,uid=1000,gid=1000,exec 0 0
    

    其他选项是:

    • x-systemd.automount为 systemd 创建一个自动挂载单元
    • x-systemd.requires=network-online.target 仅在实现网络连接后才尝试挂载
    • exec使已安装驱动器上的文件可执行。
    • 4

相关问题

  • 如何安全地重新排序分区?使用 gdisk 'sort' 选项安全吗?编辑 fstab + grub.cfg 有必要吗?

  • 是否有可能阻止 sshfs 创建 goutputstream 文件?

  • 在引导时绕过自动挂载

  • 如何从 fstab 中识别 UUID conf 或普通 dev conf

  • 回送设备的启动时 Fsck

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve