[DEBIAN] Remote Mount with SSH(리눅스에서 SSH로 원격 디렉토리 마운트하기)

클라이언트와 서버. 즉 원격지에서의 작업이나 개발을 위해선 ssh 같은 remote shell을 사용해야합니다. 오늘은 ssh 프로토콜을 이용해서 filesystem 처럼 사용하는 방법에 대해 알아볼까 합니다. (익숙해지면 이만큼 편리한게 없을정도..)

Install sshfs

리눅스에서는 sshfs라는 툴킷을 이용하여 쉽게 ssh를 이용한 원격 마운트를 진행할 수 있습니다. 아주 간편한 방법으로 안전하게 파일 시스템을 사용할 수 있죠(ftp는 저리가..)

먼저 sshfs 설치가 필요합니다. 클라이언트에 패키지 매니저를 이용해서 쉽게 설치해줍니다. #> apt-get install sshfs

(당연히 서버에는 sshd가 깔려있어야겠죠)

Remote Mount sshfs

자 이제 sshfs를 이용해서 마운트를 할 차례입니다.

sshfs [사용자ID@서버주소:/디렉토리] [마운트_지점]

공식 Description은..


SSHFS(1)                                                                                      User Commands                                                                                      SSHFS(1)

NAME
       SSHFS - filesystem client based on ssh

SYNOPSIS
   mounting
       sshfs [user@]host:[dir] mountpoint [options]

   unmounting
       fusermount -u mountpoint

DESCRIPTION
       SSHFS  (Secure  SHell  FileSystem) is a file system for Linux (and other operating systems with a FUSE implementation, such as Mac OS X or FreeBSD) capable of operating on files on a remote com‐
       puter using just a secure shell login on the remote computer. On the local computer where the SSHFS is mounted, the implementation makes use of the FUSE (Filesystem in Userspace) kernel  module.
       The  practical  effect  of  this is that the end user can seamlessly interact with remote files being securely served over SSH just as if they were local files on his/her computer. On the remote
       computer the SFTP subsystem of SSH is used.

       If host is a numeric IPv6 address, it needs to be enclosed in square brackets.

이렇습니다.

#> sshfs test@192.168.0.9:/var/www/html/ ~/test -o allow_other test@192.168.0.9’s password:

※ 여기서 allow_other 옵션으로 다른 사용자(일반 사용자)도 접근할 수 있게 권한을 줌

위와 같은 방법으로 마운트하여 쉽게 작업할 수 있습니다.

#> df | grep 192.168.0.9 test@192.168.0.9:/var/www/html/ 229066996 6925520 210482 ..

Reference

https://en.wikipedia.org/wiki/SSHFS