Mac SSH 掛載當作硬碟使用

下午4:18:00


1.安裝 FUSE for macOS && SSHFS

https://osxfuse.github.io/

在左邊的兩個下載安裝





#!/bin/bash

# Config ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

USERNAME=xxx        # SSH登入名稱
PASSWORD=xxx        # SSH登入密碼
HOST=xxx            # ip位置or網址

REMOTEDIR=xxx       # 掛載位置, 例如/18T/dev/

VOLUMENAME=xxx      # 在mac上掛載後的名稱 

# –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

MOUNTROOT=~/mount/
MOUNT=$MOUNTROOT/$VOLUMENAME

# Check if Mount  Folder exists, if not create it
# when done call Mount()
CheckIfMountFolderExists() {
  if [ -d "$MOUNT" ]; then
    umount $MOUNT
    echo "exists, call mount"
    # Mount
  else
    echo "not exists"
    mkdir $MOUNT
  fi
}


# Check if Mount Root Folder exists, if not create and hide it
CheckIfMountROOTFolderExists() {
  if [ -d "$MOUNTROOT" ]; then
    echo "exists, call CheckIfMountFolderExists"
    CheckIfMountFolderExists
  else
    echo "not exists"
    mkdir $MOUNTROOT
    chflags hidden $MOUNTROOT # Hide folder
    CheckIfMountFolderExists
  fi
}
CheckIfMountROOTFolderExists

echo $PASSWORD | sshfs -o password_stdin -o volname=$VOLUMENAME -o local $USERNAME@$HOST:$REMOTEDIR $MOUNT

# Execute the SSHFS Mount command
# Mount() {
#     echo "mount..."
#   # echo $PASSWORD | sshfs -o password_stdin -o volname=$VOLUMENAME -o local $USERNAME@$HOST:$REMOTEDIR $MOUNT
#   # echo $PASSWORD | sshfs $USERNAME@$HOST:$REMOTEDIR $MOUNT -o password_stdin
# }

# guess what :)
echo "done"
  

把上面的儲存為 xxx.command 檔案

點擊就會掛載了
技術提供:Blogger.