비표준 SSH 포트에서 SSH 키를 사용하여 sshfs에 대한 fstab 항목을 생성하는 방법

비표준 SSH 포트에서 SSH 키를 사용하여 sshfs에 대한 fstab 항목을 생성하는 방법

서버는 포트 "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 공개 키를 추가해야 합니다.

어떻게 해야 하나요?

답변1

/etc/fstab찾고 있는 항목은 다음과 같습니다.

사용법 ,port=PORTNUMBER,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   

미드의 SSH(Secure Shell) 가이드

fstab에 sshfs 원격 디렉터리를 마운트하는 방법

mount -a 없이 fstab을 사용하여 sshfs를 자동으로 마운트하세요.

SSHFS는 검토할 수 있는 많은 명령줄 옵션을 허용합니다. 예를 들어 원격 시스템의 SSH 서버가 포트 22 대신 포트 12345에서 실행 중인 경우 다음을 수행합니다.

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

답변2

이 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.automountsystemd용 자동 마운트 장치 생성
  • x-systemd.requires=network-online.target 네트워크 연결이 설정된 후에만 시도하십시오.
  • exec마운트된 드라이브의 파일을 실행 가능하게 만듭니다.

관련 정보