MacbookのFinderにssh接続先のサーバーを表示する方法【2024】

## 🎯目的

- MacbookのFinderにssh接続先のサーバーのファイルにアクセスしたい

## 💬手順

### 1. macportのインストール
    
- [MacPorts](https://www.macports.org/install.php)からインストール


### 2. sshfsのインストール

`sudo port install sshfs`

<details><summary>実行ログ</summary>

```bash
sudo port install sshfs
Password:
--->  Computing dependencies for sshfs
The following dependencies will be installed: 
 autoconf
 automake
 bzip2
 expat
 gettext
 gettext-runtime
 gettext-tools-libs
 glib2
 libedit
 libelf
 libffi
 libiconv
 libtextstyle
 libtool
 m4
 macfuse
 ncurses
 openssl
 openssl3
 pcre2
 pkgconfig
 python312
 python3_select
 python3_select-312
 python_select
 python_select-312
 sqlite3
 xz
 zlib
Continue? [Y/n]: Y
--->  Fetching archive for libiconv
--->  Attempting to fetch libiconv-1.17_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/libiconv
--->  Attempting to fetch libiconv-1.17_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libiconv
--->  Installing libiconv @1.17_0
--->  Activating libiconv @1.17_0
--->  Cleaning libiconv
--->  Fetching archive for gettext-runtime
--->  Attempting to fetch gettext-runtime-0.21.1_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/gettext-runtime
--->  Attempting to fetch gettext-runtime-0.21.1_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/gettext-runtime
--->  Installing gettext-runtime @0.21.1_0
--->  Activating gettext-runtime @0.21.1_0
--->  Cleaning gettext-runtime
--->  Fetching archive for m4
--->  Attempting to fetch m4-1.4.19_1.darwin_23.x86_64.tbz2 from https://packages.macports.org/m4
--->  Attempting to fetch m4-1.4.19_1.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/m4
--->  Installing m4 @1.4.19_1
--->  Activating m4 @1.4.19_1
--->  Cleaning m4
--->  Fetching archive for autoconf
--->  Attempting to fetch autoconf-2.71_2.any_any.noarch.tbz2 from https://packages.macports.org/autoconf
--->  Attempting to fetch autoconf-2.71_2.any_any.noarch.tbz2.rmd160 from https://packages.macports.org/autoconf
--->  Installing autoconf @2.71_2
--->  Activating autoconf @2.71_2
--->  Cleaning autoconf
--->  Fetching archive for automake
--->  Attempting to fetch automake-1.16.5_0.any_any.noarch.tbz2 from https://packages.macports.org/automake
--->  Attempting to fetch automake-1.16.5_0.any_any.noarch.tbz2.rmd160 from https://packages.macports.org/automake
--->  Installing automake @1.16.5_0
--->  Activating automake @1.16.5_0
--->  Cleaning automake
--->  Fetching archive for ncurses
--->  Attempting to fetch ncurses-6.4_1.darwin_23.x86_64.tbz2 from https://packages.macports.org/ncurses
--->  Attempting to fetch ncurses-6.4_1.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/ncurses
--->  Installing ncurses @6.4_1
--->  Activating ncurses @6.4_1
--->  Cleaning ncurses
--->  Fetching archive for libtextstyle
--->  Attempting to fetch libtextstyle-0.21.1_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/libtextstyle
--->  Attempting to fetch libtextstyle-0.21.1_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libtextstyle
--->  Installing libtextstyle @0.21.1_0
--->  Activating libtextstyle @0.21.1_0
--->  Cleaning libtextstyle
--->  Fetching archive for gettext-tools-libs
--->  Attempting to fetch gettext-tools-libs-0.21.1_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/gettext-tools-libs
--->  Attempting to fetch gettext-tools-libs-0.21.1_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/gettext-tools-libs
--->  Installing gettext-tools-libs @0.21.1_0
--->  Activating gettext-tools-libs @0.21.1_0
--->  Cleaning gettext-tools-libs
--->  Fetching archive for gettext
--->  Attempting to fetch gettext-0.21.1_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/gettext
--->  Attempting to fetch gettext-0.21.1_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/gettext
--->  Installing gettext @0.21.1_0
--->  Activating gettext @0.21.1_0
--->  Cleaning gettext
--->  Fetching archive for libelf
--->  Attempting to fetch libelf-0.8.13_2.darwin_23.x86_64.tbz2 from https://packages.macports.org/libelf
--->  Attempting to fetch libelf-0.8.13_2.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libelf
--->  Installing libelf @0.8.13_2
--->  Activating libelf @0.8.13_2
--->  Cleaning libelf
--->  Fetching archive for libffi
--->  Attempting to fetch libffi-3.4.4_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/libffi
--->  Attempting to fetch libffi-3.4.4_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libffi
--->  Installing libffi @3.4.4_0
--->  Activating libffi @3.4.4_0
--->  Cleaning libffi
--->  Fetching archive for bzip2
--->  Attempting to fetch bzip2-1.0.8_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/bzip2
--->  Attempting to fetch bzip2-1.0.8_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/bzip2
--->  Installing bzip2 @1.0.8_0
--->  Activating bzip2 @1.0.8_0
--->  Cleaning bzip2
--->  Fetching archive for libedit
--->  Attempting to fetch libedit-20230828-3.1_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/libedit
--->  Attempting to fetch libedit-20230828-3.1_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libedit
--->  Installing libedit @20230828-3.1_0
--->  Activating libedit @20230828-3.1_0
--->  Cleaning libedit
--->  Fetching archive for zlib
--->  Attempting to fetch zlib-1.3_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/zlib
--->  Attempting to fetch zlib-1.3_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/zlib
--->  Installing zlib @1.3_0
--->  Activating zlib @1.3_0
--->  Cleaning zlib
--->  Fetching archive for pcre2
--->  Attempting to fetch pcre2-10.42_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/pcre2
--->  Attempting to fetch pcre2-10.42_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/pcre2
--->  Installing pcre2 @10.42_0
--->  Activating pcre2 @10.42_0
--->  Cleaning pcre2
--->  Fetching archive for expat
--->  Attempting to fetch expat-2.5.0_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/expat
--->  Attempting to fetch expat-2.5.0_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/expat
--->  Installing expat @2.5.0_0
--->  Activating expat @2.5.0_0
--->  Cleaning expat
--->  Fetching archive for openssl3
--->  Attempting to fetch openssl3-3.2.0_1.darwin_23.x86_64.tbz2 from https://packages.macports.org/openssl3
--->  Attempting to fetch openssl3-3.2.0_1.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/openssl3
--->  Installing openssl3 @3.2.0_1
--->  Activating openssl3 @3.2.0_1
--->  Cleaning openssl3
--->  Fetching archive for openssl
--->  Attempting to fetch openssl-3_16.darwin_23.x86_64.tbz2 from https://packages.macports.org/openssl
--->  Attempting to fetch openssl-3_16.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/openssl
--->  Installing openssl @3_16
--->  Activating openssl @3_16
--->  Cleaning openssl
--->  Fetching archive for python3_select
--->  Attempting to fetch python3_select-0.1_0.darwin_23.noarch.tbz2 from https://packages.macports.org/python3_select
--->  Attempting to fetch python3_select-0.1_0.darwin_23.noarch.tbz2.rmd160 from https://packages.macports.org/python3_select
--->  Installing python3_select @0.1_0
--->  Activating python3_select @0.1_0
--->  Cleaning python3_select
--->  Fetching archive for python3_select-312
--->  Attempting to fetch python3_select-312-0.1_1.any_any.noarch.tbz2 from https://packages.macports.org/python3_select-312
--->  Attempting to fetch python3_select-312-0.1_1.any_any.noarch.tbz2.rmd160 from https://packages.macports.org/python3_select-312
--->  Installing python3_select-312 @0.1_1
--->  Activating python3_select-312 @0.1_1
--->  Cleaning python3_select-312
--->  Fetching archive for python_select
--->  Attempting to fetch python_select-0.3_10.darwin_23.noarch.tbz2 from https://packages.macports.org/python_select
--->  Attempting to fetch python_select-0.3_10.darwin_23.noarch.tbz2.rmd160 from https://packages.macports.org/python_select
--->  Installing python_select @0.3_10
--->  Activating python_select @0.3_10
--->  Cleaning python_select
--->  Fetching archive for python_select-312
--->  Attempting to fetch python_select-312-0.3_1.any_any.noarch.tbz2 from https://packages.macports.org/python_select-312
--->  Attempting to fetch python_select-312-0.3_1.any_any.noarch.tbz2.rmd160 from https://packages.macports.org/python_select-312
--->  Installing python_select-312 @0.3_1
--->  Activating python_select-312 @0.3_1
--->  Cleaning python_select-312
--->  Fetching archive for sqlite3
--->  Attempting to fetch sqlite3-3.45.0_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/sqlite3
--->  Attempting to fetch sqlite3-3.45.0_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/sqlite3
--->  Installing sqlite3 @3.45.0_0
--->  Activating sqlite3 @3.45.0_0
--->  Cleaning sqlite3
--->  Fetching archive for xz
--->  Attempting to fetch xz-5.4.5_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/xz
--->  Attempting to fetch xz-5.4.5_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/xz
--->  Installing xz @5.4.5_0
--->  Activating xz @5.4.5_0
--->  Cleaning xz
--->  Fetching archive for python312
--->  Attempting to fetch python312-3.12.1_0+lto+optimizations.darwin_23.x86_64.tbz2 from https://packages.macports.org/python312
--->  Attempting to fetch python312-3.12.1_0+lto+optimizations.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/python312
--->  Installing python312 @3.12.1_0+lto+optimizations
--->  Activating python312 @3.12.1_0+lto+optimizations
--->  Cleaning python312
--->  Fetching archive for glib2
--->  Attempting to fetch glib2-2.78.3_1+x11.darwin_23.x86_64.tbz2 from https://packages.macports.org/glib2
--->  Attempting to fetch glib2-2.78.3_1+x11.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/glib2
--->  Installing glib2 @2.78.3_1+x11
--->  Activating glib2 @2.78.3_1+x11
--->  Cleaning glib2
--->  Fetching archive for libtool
--->  Attempting to fetch libtool-2.4.7_1.darwin_23.x86_64.tbz2 from https://packages.macports.org/libtool
--->  Attempting to fetch libtool-2.4.7_1.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/libtool
--->  Installing libtool @2.4.7_1
--->  Activating libtool @2.4.7_1
--->  Cleaning libtool
--->  Fetching archive for macfuse
--->  Attempting to fetch macfuse-4.5.0_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/macfuse
--->  Attempting to fetch macfuse-4.5.0_0.darwin_23.x86_64.tbz2 from https://kmq.jp.packages.macports.org/macfuse
--->  Attempting to fetch macfuse-4.5.0_0.darwin_23.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/macfuse
--->  Fetching distfiles for macfuse
--->  Attempting to fetch macfuse-4.5.0.dmg from https://github.com/osxfuse/osxfuse/releases/download/macfuse-4.5.0
--->  Verifying checksums for macfuse
--->  Extracting macfuse
--->  Configuring macfuse
--->  Building macfuse
--->  Staging macfuse into destroot
--->  Installing macfuse @4.5.0_0
--->  Activating macfuse @4.5.0_0
--->  Cleaning macfuse
--->  Fetching archive for pkgconfig
--->  Attempting to fetch pkgconfig-0.29.2_0.darwin_23.x86_64.tbz2 from https://packages.macports.org/pkgconfig
--->  Attempting to fetch pkgconfig-0.29.2_0.darwin_23.x86_64.tbz2.rmd160 from https://packages.macports.org/pkgconfig
--->  Installing pkgconfig @0.29.2_0
--->  Activating pkgconfig @0.29.2_0
--->  Cleaning pkgconfig
--->  Fetching archive for sshfs
--->  Attempting to fetch sshfs-2.10_1.darwin_23.x86_64.tbz2 from https://packages.macports.org/sshfs
--->  Attempting to fetch sshfs-2.10_1.darwin_23.x86_64.tbz2 from https://kmq.jp.packages.macports.org/sshfs
--->  Attempting to fetch sshfs-2.10_1.darwin_23.x86_64.tbz2 from http://jog.id.packages.macports.org/macports/packages/sshfs
--->  Fetching distfiles for sshfs
--->  Attempting to fetch sshfs-2.10.tar.gz from https://codeload.github.com/libfuse/sshfs/legacy.tar.gz/sshfs-2.10?dummy=
--->  Verifying checksums for sshfs
--->  Extracting sshfs
--->  Applying patches to sshfs
--->  Configuring sshfs
--->  Building sshfs                                     
--->  Staging sshfs into destroot                        
--->  Installing sshfs @2.10_1                           
--->  Activating sshfs @2.10_1
--->  Cleaning sshfs
--->  Updating database of binaries
--->  Scanning binaries for linking errors
--->  No broken files found.
--->  No broken ports found.
--->  Some of the ports you installed have notes:
  macfuse has the following notes:
    Run the following before using macFUSE:
    
        sudo ln -fsn /opt/local/Library/Filesystems/macfuse.fs /Library/Filesystems/macfuse.fs
  python312 has the following notes:
    To make this the default Python or Python 3 (i.e., the version run by the 'python' or 'python3' commands), run one or both of:
    
        sudo port select --set python python312
        sudo port select --set python3 python312
```
</details>


- Benjamin Fleischerのフォルダアクセスを許可するかmacbookの警告が出ますが、[こちらの記事](https://discussions.apple.com/thread/253261369?sortBy=best)など５つぐらい記事を読んで大丈夫そうと判断して許可。
- sshfsを入れた後、再起動する


### 3. macfuseをインストール（https://osxfuse.github.io/）
    
```bash
brew install macfuse
```
 
### 4. sshfsを用いて以下のコマンドを入力

```bash
sshfs [user]@[host]:[dir] ~[local path] -o IdentityFile=~/.ssh/[id_ras name]
```

## 🎉結果

- macFuse Volume 0 (sshfs)という場所にssh接続先の指定したディレクトリ以下のフォルダが表示される



## 📊参照

- [SSHサーバをMacにマウントする](https://www.notion.so/Macbook-Finder-ssh-596460a74a9c4cceb3cc67ecd1b0675c?pvs=21)
- [sshfs](https://ports.macports.org/port/sshfs/)
- [macFUSE + SSHFSでUbuntuのディレクトリをMacにマウントする](https://qiita.com/h_tyokinuhata/items/8a0669c149796aec21a9)