Skip to content

Instantly share code, notes, and snippets.

@toabr
Created June 29, 2024 16:53
Show Gist options
  • Select an option

  • Save toabr/f65b416645cadebfa2c460dbc048229a to your computer and use it in GitHub Desktop.

Select an option

Save toabr/f65b416645cadebfa2c460dbc048229a to your computer and use it in GitHub Desktop.
script to mount remote directory via sshfs on demand
#!/bin/bash
# sript to mount remote directory via sshfs on demand
REMOTE="user@remote-server:/path/"
OPTIONS="idmap=user,uid=1001,gid=1001"
SSHKEY="/home/user/.ssh/remote_key"
MOUNTPOINT="/mnt/remote"
# check if its already mounted
if grep -qs "$MOUNTPOINT" /proc/mounts; then
echo "Already mounted"
thunar "$MOUNTPOINT"
else
echo "Not mounted"
sshfs -o "$OPTIONS",identityfile="$SSHKEY" "$REMOTE" "$MOUNTPOINT"
# check mount success
if [ $? -eq 0 ]; then
echo "Mount success"
thunar "$MOUNTPOINT"
else
echo "Something went wrong"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment